#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, mx = 0;
  vector<pair<int, int> > vc;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    vc.push_back({a, b});
  }
  sort(vc.begin(), vc.end());
  mx = vc[0].second;
  for (int i = 1; i < n; i++) {
    if (vc[i].second >= mx) {
      mx = vc[i].second;
    } else {
      mx = vc[i].first;
    }
  }
  cout << mx;
}
