#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
const long double eps = 1e-8;
const int INF = 1E9;
const int MAXN = 100500;
const int P = 1999;
int n, k, ans;
vector<pair<int, int> > a;
int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort((a).begin(), (a).end());
  int cur = a[0].second;
  for (int i = 1; i < n - 1; i++) {
    if (a[i].second < cur)
      cur = a[i].first;
    else
      cur = max(cur, a[i].second);
    if (cur > a[n - 1].second) {
      cout << a[n - 1].first;
      return 0;
    }
  }
  cout << a[n - 1].second;
  return 0;
}
