#include <bits/stdc++.h>
using namespace std;
static char _buf[1 << 16];
int _pos = 1;
int _cap = 1;
inline char nextChar() {
  if (_cap == 0) return 0;
  if (_pos == _cap) {
    _cap = (int)fread(_buf, 1, 1 << 16, stdin);
    if (_cap == 0) return 0;
    _pos = 0;
  }
  return _buf[_pos++];
}
template <class T>
T nextInt() {
  char c = nextChar();
  while (isspace(c)) c = nextChar();
  int sign = 1;
  if (c == '-') {
    sign = -1;
    c = nextChar();
  }
  T res = 0;
  while (isdigit(c)) {
    res = res * 10 + c - '0';
    c = nextChar();
  }
  return res * sign;
}
struct E {
  int a;
  int b;
} e[1000000];
int n;
int x[2000000];
int used[1000000];
int d[1000000];
int f[1000000];
int DFS(int i, int maxday) {
  if (used[i] != -1) return 0;
  used[i] = 1;
  if (f[e[i].a] == 0 || DFS(f[e[i].a], maxday)) {
    d[i] = e[i].a;
    f[e[i].a] = i;
    return 1;
  }
  if (e[i].b < maxday)
    if (f[e[i].b] == 0 || DFS(f[e[i].b], maxday)) {
      d[i] = e[i].b;
      f[e[i].b] = i;
      return 1;
    }
  return 0;
}
bool Check(int maxday) {
  for (int i = 0; i < n; i++)
    if (e[i].a > maxday && e[i].b > maxday) return false;
  memset(f, -1, sizeof(int) * (maxday + 1));
  memset(d, -1, sizeof(int) * n);
  int f = 0;
  while (true) {
    memset(used, -1, sizeof(int) * n);
    int df = 0;
    for (int i = 0; i < n; i++)
      if (d[i] == -1) df += DFS(i, maxday);
    f += df;
    if (f == n) return true;
    if (df == 0) return f == n;
  }
}
int main() {
  int n = nextInt<int>();
  for (int i = 0; i < n; i++) {
    x[2 * i] = e[i].a = nextInt<int>();
    x[2 * i + 1] = e[i].b = nextInt<int>();
  }
  sort(x, x + 2 * n);
  int xc = (int)(unique(x, x + 2 * n) - x);
  if (xc < n) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    e[i].a = (int)(lower_bound(x, x + xc, e[i].a) - x);
    e[i].b = (int)(lower_bound(x, x + xc, e[i].b) - x);
  }
  if (!Check(xc - 1)) {
    puts("-1");
    return 0;
  }
  int l = n - 1;
  int r = xc - 1;
  while (l < r) {
    int m = (l + r) >> 1;
    if (Check(m))
      r = m;
    else
      l = m + 1;
  }
  cout << x[l] << endl;
  return 0;
}
