#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  pair<long long int, long long int> p[a];
  for (int i = 0; i < a; i++) {
    long long int b, c;
    cin >> b >> c;
    p[i] = make_pair(b, c);
  }
  sort(p, p + a);
  long long int maxi = 0;
  for (int i = 0; i < a; i++) {
    if (maxi <= p[i].second) {
      maxi = p[i].second;
    } else
      maxi = p[i].first;
  }
  cout << maxi << endl;
  return 0;
}
