#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  pair<long long, long long> a[n];
  for (long long i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  sort(a, a + n);
  long long ans = min(a[0].first, a[0].second);
  for (long long i = 1; i < n; i++) {
    if (a[i].second <= a[i].first && a[i].second >= ans)
      ans = a[i].second;
    else
      ans = a[i].first;
  }
  cout << ans;
  return 0;
}
