#include <bits/stdc++.h>
using namespace std;
map<int, set<int> > MS;
int n;
int main() {
  bool flag = true;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    MS[a].insert(b);
  }
  auto pt = MS.rbegin();
  int l = *pt->second.begin(), r = *pt->second.rbegin();
  for (auto it = MS.rbegin(); it != MS.rend(); ++it) {
    if (it == pt) continue;
    int tl = *it->second.begin(), tr = *it->second.rbegin();
    if (l >= it->first) {
      l = it->first;
    } else if (l >= tr) {
      l = tl;
    } else {
      flag = false;
      break;
    }
  }
  if (flag)
    printf("%d\n", r);
  else
    printf("%d\n", pt->first);
  return 0;
}
