#include <bits/stdc++.h>
using namespace std;
int p[2000010];
struct pr {
  int l, r;
} a[1000010];
bool operator<(pr a, pr b) { return a.l == b.l ? a.r < b.r : a.l < b.l; }
int n, m, M, v[2000010];
bool check(int lim) {
  int i, cnt;
  M++;
  for (i = 1, cnt = 0; i <= n; i++) {
    if (a[i].l <= lim && v[a[i].l] != M) {
      v[a[i].l] = M;
      cnt++;
    }
    if (a[i].r <= lim && v[a[i].r] != M) {
      v[a[i].r] = M;
      cnt++;
    }
    if (cnt < i) return 0;
  }
  M++;
  for (i = n, cnt = 0; i > 0; i--) {
    if (a[i].l <= lim && v[a[i].l] != M) {
      v[a[i].l] = M;
      cnt++;
    }
    if (a[i].r <= lim && v[a[i].r] != M) {
      v[a[i].r] = M;
      cnt++;
    }
    if (cnt < n - i + 1) return 0;
  }
  return 1;
}
int main() {
  int i, l, r, mid, ans;
  scanf("%d", &n);
  m = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].l, &a[i].r);
    p[++m] = a[i].l;
    p[++m] = a[i].r;
  }
  sort(p + 1, p + m + 1);
  m = unique(p + 1, p + m + 1) - p - 1;
  for (i = 1; i <= n; i++) {
    a[i].l = lower_bound(p + 1, p + m + 1, a[i].l) - p;
    a[i].r = lower_bound(p + 1, p + m + 1, a[i].r) - p;
  }
  sort(a + 1, a + n + 1);
  ans = -1;
  l = 1;
  r = m;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d", ~ans ? p[ans] : -1);
}
