#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, M = N << 1, L = M << 1;
int To[L], Ne[L], St[M], d[M], en, a[N], b[N], t[M], tn, n;
inline __attribute__((always_inline)) void addedge(int u, int v) {
  To[++en] = v, Ne[en] = St[u], St[u] = en;
  To[++en] = u, Ne[en] = St[v], St[v] = en;
  ++d[u], ++d[v];
}
bool vi[M];
struct rt {
  int d, n;
  inline __attribute__((always_inline)) rt(int d = 0, int n = 0) : d(d), n(n) {}
};
inline __attribute__((always_inline)) rt operator+(const rt& a, const rt& b) {
  return rt(a.d + b.d, a.n + b.n);
}
rt dfs(int u) {
  if (vi[u]) return rt(0, 0);
  vi[u] = 1;
  rt ret = rt(d[u], 1);
  for (int i = St[u]; i; i = Ne[i]) ret = ret + dfs(To[i]);
  return ret;
}
inline __attribute__((always_inline)) bool check(int x) {
  if (x > tn) return 0;
  fill(St + 1, St + 1 + tn, 0), fill(d + 1, d + tn + 1, 0), en = 0;
  for (int i = 1; i <= n; ++i) {
    if (x < a[i])
      return 0;
    else if (a[i] <= x && x < b[i])
      addedge(a[i], a[i]);
    else
      addedge(a[i], b[i]);
  }
  fill(vi + 1, vi + 1 + tn, 0);
  for (int i = 1; i <= tn; ++i) {
    if (!vi[i]) {
      rt res = dfs(i);
      if ((res.d >> 1) > res.n) return 0;
    }
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    t[++tn] = a[i], t[++tn] = b[i];
  }
  sort(t + 1, t + tn + 1);
  tn = unique(t + 1, t + tn + 1) - t - 1;
  for (int i = 1; i <= n; ++i) {
    a[i] = lower_bound(t + 1, t + tn + 1, a[i]) - t;
    b[i] = lower_bound(t + 1, t + tn + 1, b[i]) - t;
  }
  int l = 1, r = tn;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  assert(l > 0);
  if (!check(l))
    puts("-1");
  else
    printf("%d\n", t[check(r) ? r : l]);
  return 0;
}
