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