#include <bits/stdc++.h>
using namespace std;
char gchar() {
  static char tbuf1[1000], *tmp_st = tbuf1, *tmp_ed = tbuf1;
  if (tmp_st == tmp_ed) {
    int len = fread(tbuf1, 1, 1000, stdin);
    if (len == 0) return -1;
    tmp_ed = tbuf1 + len;
    tmp_st = tbuf1;
  }
  return *(tmp_st++);
}
inline bool gn(int& first) {
  char c, sg = 0;
  while (c = gchar(), (c > '9' || c < '0') && c != '-' && ~c)
    ;
  if (c == -1) return 0;
  for ((c == '-' ? sg = 1, c = gchar() : 0), first = 0; c >= '0' && c <= '9';
       c = gchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
  return 1;
}
int id[2000100], arr[2000100];
int mr[2000100], vst[2000100], res;
int n, a[2000100], b[2000100];
int head[2000100], nxt[2000100], to[2000100], E;
int nn = 0;
void init() {
  E = 0;
  for (int i = 0; i <= n + 2; i++) head[i] = -1;
  for (int i = 0; i <= nn + 2; i++) mr[i] = -1;
}
void add(int u, int v) {
  nxt[E] = head[u];
  to[E] = v;
  head[u] = E++;
}
int bpm(int u) {
  for (int e = head[u]; ~e; e = nxt[e]) {
    int v = to[e];
    if (mr[v] == -1) {
      mr[v] = u;
      return 1;
    }
  }
  for (int e = head[u]; ~e; e = nxt[e]) {
    int v = to[e];
    if (vst[v] == res) continue;
    vst[v] = res;
    if (bpm(mr[v])) {
      mr[v] = u;
      return 1;
    }
  }
  return 0;
}
inline int solve(int md) {
  init();
  for (int i = 1; i <= n; i++) {
    if (a[i] <= md) add(i, a[i]);
    if (b[i] <= md) add(i, b[i]);
  }
  for (int i = 1; i <= n; i++) {
    res++;
    if (!bpm(i)) return 0;
  }
  return 1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    gn(a[i]);
    gn(b[i]);
    arr[nn++] = a[i];
    arr[nn++] = b[i];
  }
  sort(arr, arr + nn);
  nn = unique(arr, arr + nn) - arr;
  for (int i = 1; i <= nn; i++) id[i] = arr[i - 1];
  int st = upper_bound(arr, arr + nn, n) - arr;
  for (int i = 1; i <= n; i++) {
    a[i] = upper_bound(arr, arr + nn, a[i]) - arr;
    b[i] = upper_bound(arr, arr + nn, b[i]) - arr;
    st = max(st, a[i]);
  }
  st--;
  int ed = nn + 1;
  if (!solve(3 * n)) return puts("-1"), 0;
  while (st + 1 < ed) {
    int md = st + ed >> 1;
    if (solve(md))
      ed = md;
    else
      st = md;
  }
  cout << id[ed] << endl;
}
