#include <bits/stdc++.h>
using namespace std;
int main() {
  std::iostream::sync_with_stdio(false);
  int n;
  cin >> n;
  std::vector<pair<int, int> > v(n);
  int i;
  for (i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    v[i] = make_pair(a, b);
  }
  sort(v.begin(), v.end());
  int t = v[0].second;
  for (i = 1; i < n; i++) {
    if (v[i].second >= t) {
      t = v[i].second;
    } else {
      t = v[i].first;
    }
  }
  cout << t << endl;
  return 0;
}
