#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cout.precision(20);
  int n;
  cin >> n;
  vector<pair<int, int> > ab(n);
  for (int i = 0; i < n; i++) cin >> ab[i].first >> ab[i].second;
  sort((ab).begin(), (ab).end());
  int md = ab[0].second;
  for (int i = 1; i < n; i++) {
    if (md <= ab[i].second)
      md = ab[i].second;
    else
      md = ab[i].first;
  }
  cout << md;
}
