#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[54321];
int main() {
  int n;
  cin >> n;
  int mxf, mxs;
  mxf = mxs = -1;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
    mxf = max(mxf, p[i].first);
    mxs = max(mxs, p[i].second);
  }
  sort(p, p + n);
  bool flag = true;
  for (int i = 0; i < n - 1; i++)
    if (p[i].second > p[i + 1].second) {
      flag = false;
      break;
    }
  if (flag) {
    cout << mxs << endl;
  } else {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (ans <= p[i].second)
        ans = p[i].second;
      else
        ans = p[i].first;
    }
    cout << ans << endl;
  }
}
