#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  if (p1 == p2) {
    p2 = (p1 = buf) + fread(buf, 1, 100000, stdin);
    if (p1 == p2) return EOF;
  }
  return *p1++;
}
inline void read(int &x) {
  char c = nc(), b = 1;
  if (c == EOF) {
    x = -1;
    return;
  }
  for (; !(c >= '0' && c <= '9'); c = nc())
    if (c == '-') b = -1;
  for (x = 0; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
  x *= b;
}
const int maxn = 2e6 + 5;
int a[maxn >> 1], b[maxn >> 1], n;
int tmp[maxn], num;
bool vis[maxn];
int match[maxn];
int cle[maxn], top;
int cle2[maxn], top2;
bool dfs(int i, int up) {
  if (!vis[a[i]]) {
    vis[a[i]] = 1;
    cle[++top] = a[i];
    if (!match[a[i]]) {
      match[a[i]] = i;
      return 1;
    }
    if (dfs(match[a[i]], up)) {
      match[a[i]] = i;
      return 1;
    }
  }
  if (b[i] <= up && !vis[b[i]]) {
    vis[b[i]] = 1;
    cle[++top] = b[i];
    if (!match[b[i]]) {
      match[b[i]] = i;
      cle2[++top2] = b[i];
      return 1;
    }
    if (dfs(match[b[i]], up)) {
      match[b[i]] = i;
      return 1;
    }
  }
  return 0;
}
bool check(int up) {
  while (top2) {
    match[cle2[top2--]] = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] > up) return 0;
  }
  for (int i = 1; i <= n; i++) {
    while (top) {
      vis[cle[top--]] = 0;
    }
    if (!dfs(i, up)) {
      return 0;
    }
  }
  return 1;
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(a[i]), read(b[i]);
    tmp[++num] = a[i];
    tmp[++num] = b[i];
  }
  sort(tmp + 1, tmp + 1 + num);
  num = unique(tmp + 1, tmp + 1 + num) - tmp - 1;
  int mi = 1e9, ma = -1;
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(tmp + 1, tmp + 1 + num, a[i]) - tmp;
    b[i] = lower_bound(tmp + 1, tmp + 1 + num, b[i]) - tmp;
    mi = min(mi, a[i]);
    ma = max(ma, b[i]);
  }
  int l = mi, r = ma;
  if (check(l)) return 0 * printf("%d\n", tmp[l]);
  if (!check(r)) return 0 * printf("-1\n");
  while (r - l > 1) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%d\n", tmp[r]);
}
