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