#include <bits/stdc++.h>
using std::max;
using std::min;
using std::swap;
int n, vis[1000005];
int g[1000005], tot;
int pre[1000005 << 1];
struct Node {
  int a, b;
  friend bool operator<(Node x, Node y) {
    return x.a < y.a or x.a == y.a and x.b < y.b;
  }
} node[1000005];
int getint() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
int dfs(int now, int tme) {
  if (vis[now] == tme) return 0;
  vis[now] = tme;
  if (!pre[node[now].a] or dfs(pre[node[now].a], tme)) {
    pre[node[now].a] = now;
    return 1;
  }
  if (!pre[node[now].b] or dfs(pre[node[now].b], tme)) {
    pre[node[now].b] = now;
    return 1;
  }
  return 0;
}
signed main() {
  n = getint();
  for (int i = 1; i <= n; i++)
    g[++tot] = node[i].a = getint(), g[++tot] = node[i].b = getint();
  std::sort(g + 1, g + 1 + tot);
  tot = std::unique(g + 1, g + 1 + tot) - g - 1;
  for (int i = 1; i <= n; i++)
    node[i].a = std::lower_bound(g + 1, g + 1 + tot, node[i].a) - g,
    node[i].b = std::lower_bound(g + 1, g + 1 + tot, node[i].b) - g;
  int ans = 0;
  std::sort(node + 1, node + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (dfs(i, i))
      ;
    else {
      printf("-1");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (pre[node[i].a] == i)
      ans = max(ans, node[i].a);
    else if (pre[node[i].b] == i)
      ans = max(ans, node[i].b);
  }
  printf("%d\n", g[ans]);
  return 0;
}
