#include <bits/stdc++.h>
using namespace std;
struct IO {
  char buf[(1 << 20)], *p1, *p2;
  char pbuf[(1 << 20)], *pp;
  IO() : p1(buf), p2(buf), pp(pbuf) {}
  ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }
  inline char gc() {
    if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin);
    return p1 == p2 ? ' ' : *p1++;
  }
  inline bool blank(char ch) {
    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
  }
  template <class T>
  inline void read(T &x) {
    register double tmp = 1;
    register bool sign = 0;
    x = 0;
    register char ch = gc();
    for (; !(ch >= '0' && ch <= '9'); ch = gc())
      if (ch == '-') sign = 1;
    for (; (ch >= '0' && ch <= '9'); ch = gc()) x = x * 10 + (ch - '0');
    if (ch == '.')
      for (ch = gc(); (ch >= '0' && ch <= '9'); ch = gc())
        tmp /= 10.0, x += tmp * (ch - '0');
    if (sign) x = -x;
  }
  inline void read(char *s) {
    register char ch = gc();
    for (; blank(ch); ch = gc())
      ;
    for (; !blank(ch); ch = gc()) *s++ = ch;
    *s = 0;
  }
  inline void read(char &c) {
    for (c = gc(); blank(c); c = gc())
      ;
  }
  inline void push(const char &c) {
    if (pp - pbuf == (1 << 20)) fwrite(pbuf, 1, (1 << 20), stdout), pp = pbuf;
    *pp++ = c;
  }
  template <class T>
  inline void write(T x) {
    if (x < 0) x = -x, push('-');
    static T sta[35];
    T top = 0;
    do {
      sta[top++] = x % 10, x /= 10;
    } while (x);
    while (top) push(sta[--top] + '0');
  }
  template <class T>
  inline void write(T x, char lastChar) {
    write(x), push(lastChar);
  }
} io;
int n;
vector<int> lsh, a, b, f, siz, cnt;
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
bool check(int x) {
  f.resize(x + 1);
  siz.assign(x + 1, 1);
  cnt.assign(x + 1, 0);
  for (int i = 1; i <= x; ++i) f[i] = i;
  for (int i = 1; i <= n; ++i) {
    if (a[i] > x && b[i] > x) return false;
    if (a[i] > x) swap(a[i], b[i]);
    if (b[i] > x) {
      if (++cnt[find(a[i])] > siz[find(a[i])]) return false;
      continue;
    }
    int u = find(a[i]);
    int v = find(b[i]);
    if (u == v) {
      if (++cnt[u] > siz[u])
        return false;
      else
        continue;
    }
    if (siz[u] < siz[v]) swap(u, v);
    siz[u] += siz[v];
    cnt[u] += cnt[v] + 1;
    if (cnt[u] > siz[u]) return false;
    f[v] = u;
  }
  return true;
}
int main() {
  io.read(n);
  a.resize(n + 1);
  b.resize(n + 1);
  for (int i = 1; i <= n; ++i) {
    io.read(a[i]);
    io.read(b[i]);
    lsh.push_back(a[i]);
    lsh.push_back(b[i]);
  }
  sort(lsh.begin(), lsh.end());
  lsh.resize(unique(lsh.begin(), lsh.end()) - lsh.begin());
  for (int i = 1; i <= n; ++i) {
    a[i] = lower_bound(lsh.begin(), lsh.end(), a[i]) - lsh.begin() + 1;
    b[i] = lower_bound(lsh.begin(), lsh.end(), b[i]) - lsh.begin() + 1;
  }
  int l = 1, r = lsh.size() + 1;
  while (l < r) {
    int mid = (l + r - 1) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (l <= lsh.size())
    cout << lsh[l - 1];
  else
    puts("-1");
  return 0;
}
