#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  vector<pair<int, int> > d(2 * n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(), a.end());
  ;
  for (int i = 0; i < n; ++i) {
    d[2 * i].first = a[i].second;
    d[2 * i + 1].first = a[i].first;
    d[2 * i].second = i;
    d[2 * i + 1].second = i;
  }
  sort(d.begin(), d.end());
  ;
  int ind = 0;
  for (int i = 0; i < 2 * n; ++i) {
    if (d[i].second == ind) ++ind;
    if (n == ind) {
      cout << d[i].first << endl;
      return 0;
    }
  }
}
