#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
int n, a[1000015], b[1000015], p[2000015], siz[2000015], con[2000015],
    siz_e[2000015];
int a2[1000015], b2[1000015];
map<int, int> mmp;
void ini(int m) {
  for (int i = 1; i <= m; ++i) {
    p[i] = i;
    siz[i] = 1;
    siz_e[i] = 0;
  }
}
int Find(int x) { return x == p[x] ? x : p[x] = Find(p[x]); }
void uni(int x, int y) {
  x = Find(x), y = Find(y);
  p[x] = y;
  siz[y] += siz[x];
  siz_e[y] += siz_e[x] + 1;
  siz[y] = 0;
  siz_e[y] = 1;
}
bool check(int mi) {
  ini(mi);
  for (int i = 1; i <= n; ++i) {
    if (a2[i] > mi) return false;
    if (b2[i] > mi) ++siz_e[a2[i]];
  }
  for (int i = 1; i <= n; ++i) {
    if (b2[i] > mi) continue;
    uni(a2[i], b2[i]);
  }
  for (int i = 1; i <= mi; ++i) {
    if (siz_e[i] > siz[i]) return false;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    mmp[a[i]], mmp[b[i]];
  }
  int cnt = 0;
  con[0] = -1;
  for (map<int, int>::iterator it = mmp.begin(); it != mmp.end(); ++it) {
    it->second = ++cnt;
    con[cnt] = it->first;
  }
  for (int i = 1; i <= n; ++i) {
    a2[i] = mmp[a[i]];
    b2[i] = mmp[b[i]];
  }
  int s = 1, e = cnt, mi, ans = 0;
  while (s <= e) {
    mi = s + e >> 1;
    if (check(mi))
      e = (ans = mi) - 1;
    else
      s = mi + 1;
  }
  printf("%d\n", con[ans]);
  return 0;
}
