#include <bits/stdc++.h>
using namespace std;
const int N = 1E6 + 10;
struct edge {
  int v, nxt, flg;
} g[N * 2];
int head[N], sz = 1;
void add(int u, int v) {
  g[++sz] = {v, head[u], 0};
  head[u] = sz;
}
int vis[N], cnt_v, cnt_e, vs;
void dfs(int u, int lim) {
  vis[u] = 1;
  cnt_v++;
  for (int i = head[u]; i; i = g[i].nxt)
    if (g[i].flg != vs) {
      cnt_e++;
      g[i].flg = g[i ^ 1].flg = vs;
      if (!vis[g[i].v] && g[i].v <= lim) dfs(g[i].v, lim);
    }
}
int n, tim[N][2], a[N], b[N], top = 0;
int main() {
  scanf("%d", &n);
  int bot = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &tim[i][0], &tim[i][1]);
    bot = max(bot, min(tim[i][0], tim[i][1]));
    a[top++] = tim[i][0];
    a[top++] = tim[i][1];
  }
  sort(a, a + top);
  int cnt = 0;
  for (int i = 0; i < top; i++)
    if (i == 0 || a[i] != a[i - 1]) b[cnt++] = a[i];
  for (int i = 1; i <= n; i++) {
    int x = lower_bound(b, b + cnt, tim[i][0]) - b,
        y = lower_bound(b, b + cnt, tim[i][1]) - b;
    add(x, y);
    add(y, x);
  }
  int l = lower_bound(b, b + cnt, bot) - b, r = cnt - 1;
  int ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    fill(vis, vis + cnt, 0);
    bool x = 1;
    vs++;
    for (int i = 0; i < cnt; i++) {
      cnt_e = cnt_v = 0;
      if (!vis[i] && i <= mid) dfs(i, mid);
      if (cnt_e > cnt_v) {
        x = 0;
        break;
      }
    }
    if (!x)
      l = mid + 1;
    else
      r = mid - 1, ans = b[mid];
  }
  printf("%d", ans);
}
