#include <bits/stdc++.h>
using namespace std;
int f[2000005];
int used[3000005];
map<int, int> M;
int cct = 0;
struct Edge {
  int next;
  int to;
} edge[2000005];
struct node {
  int x, y;
} p[1000005];
int head[1000005];
int num[2000005];
int rnum[1000005];
int cnt = 1;
int n;
void init() {
  memset(head, -1, sizeof(head));
  cnt = 1;
}
void add(int l, int r) {
  edge[cnt].next = head[l];
  edge[cnt].to = r;
  head[l] = cnt++;
}
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
bool dfs(int x, int ttop) {
  for (int i = head[x]; i != -1; i = edge[i].next) {
    int to = edge[i].to;
    if (used[to] == ttop) {
      continue;
    }
    if (to > ttop) {
      continue;
    }
    used[to] = ttop;
    if (!f[to] || dfs(f[to], ttop)) {
      f[to] = x;
      return 1;
    }
  }
  return 0;
}
int hungary(int typ) {
  int ret = 0;
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++) {
    if (dfs(i, typ)) {
      ret++;
    }
  }
  return ret;
}
int divi() {
  int l = 1, r = cct + n;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (hungary(mid) < n) {
      l = mid + 1;
    } else {
      ans = mid;
      r = mid - 1;
    }
  }
  return ans;
}
int main() {
  n = read();
  init();
  for (int i = 1; i <= n; i++) {
    p[i].x = read(), p[i].y = read();
    num[2 * i - 1] = p[i].x;
    num[2 * i] = p[i].y;
  }
  sort(num + 1, num + 2 * n + 1);
  for (int i = 1; i <= 2 * n; i++) {
    if (num[i] != num[i - 1]) {
      M[num[i]] = ++cct;
      rnum[cct] = num[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    p[i].x = M[p[i].x];
    p[i].y = M[p[i].y];
    p[i].x += n;
    p[i].y += n;
    add(i, p[i].x);
    add(i, p[i].y);
  }
  int t = divi();
  if (t) {
    printf("%d\n", rnum[t - n]);
  } else {
    printf("-1\n");
  }
  return 0;
}
