#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  pair<long long, long long> p[n];
  for (long long i = 0; i < n; i++) {
    long long li, ri;
    cin >> li >> ri;
    p[i] = make_pair(li, ri);
  }
  sort(p, p + n);
  long long ans = -1;
  for (long long i = 0; i < n; i++) {
    if (p[i].second >= ans)
      ans = p[i].second;
    else
      ans = p[i].first;
  }
  cout << ans;
}
