#include <bits/stdc++.h>
using namespace std;
long long int b[10000], a[100000], c[100000], t[100000];
int main() {
  long long int n;
  cin >> n;
  vector<pair<int, int> > MyP;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    MyP.push_back(make_pair(x, y));
  }
  sort(MyP.begin(), MyP.end());
  long long int out_of_names = 0;
  for (int i = 0; i < n; i++) {
    if (out_of_names <= MyP[i].second) {
      out_of_names = MyP[i].second;
    } else {
      out_of_names = MyP[i].first;
    }
  }
  cout << out_of_names;
}
