#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, x, y, ans;
  cin >> n;
  vector<pair<int, int> > vp(n);
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    vp[i] = make_pair(x, y);
  }
  sort(vp.begin(), vp.end());
  ans = min(vp[0].first, vp[0].second);
  for (i = 1; i < n; i++) {
    if (vp[i].second <= vp[i].first && vp[i].second >= ans)
      ans = vp[i].second;
    else
      ans = vp[i].first;
  }
  cout << ans;
}
