#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int> > a;
  for (long long int i = 0; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    a.push_back(make_pair(x, y));
  }
  long long int cnt = 0, f = 0;
  sort(a.begin(), a.end());
  long long int best = 0;
  for (int i = 0; i < n; i++) {
    if (best <= a[i].second) {
      best = a[i].second;
    } else {
      best = a[i].first;
    }
  }
  cout << best << endl;
  return 0;
}
