#include <bits/stdc++.h>
using namespace std;
int n, l;
vector<pair<long long, long long> > v;
vector<long long> v1;
int main() {
  scanf("%d", &n);
  v.resize(n);
  v1.resize(n);
  for (int i = 0; i < n; i++) scanf("%I64d %I64d", &v[i].first, &v[i].second);
  sort(v.begin(), v.end());
  long long mx = v[0].second;
  for (int i = 1; i < n; i++) {
    if (mx > v[i].second) {
      mx = max(v[i].first, mx);
    } else {
      v[i].second = max(v[i].second, v[i - 1].second);
      mx = max(v[i].second, mx);
    }
  }
  printf("%I64d", mx);
  return 0;
}
