#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long i;
  vector<pair<long long, long long>> v;
  long long x, y;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  sort(v.begin(), v.end());
  long long mx = 0;
  long long a, b;
  i = 0;
  mx = min(v[i].first, v[i].second);
  for (i = 1; i < n; i++) {
    a = LLONG_MAX;
    b = LLONG_MAX;
    if (mx <= v[i].first) {
      a = v[i].first;
    }
    if (mx <= v[i].second) {
      b = v[i].second;
    }
    mx = min(a, b);
  }
  cout << mx;
}
