#include <bits/stdc++.h>
using namespace std;
vector<int> D[2000001], T;
vector<pair<int, int>> K;
int g[2000001], N[2000001], S[2000001];
int main() {
  int n, a, b, A, B, k = 0, amin = 0, amax = 0, t, G, v, e, L, R, I, ke;
  std::ios::sync_with_stdio(false);
  cin >> n;
  unordered_map<int, int> M;
  for (int i = 0; i < n; i++) {
    cin >> a;
    cin >> b;
    A = M[a];
    B = M[b];
    if (A == 0) {
      k++;
      M[a] = k;
      A = k;
      N[k] = a;
      K.push_back({a, k});
    }
    if (B == 0) {
      k++;
      M[b] = k;
      B = k;
      N[k] = b;
      K.push_back({b, k});
    }
    D[A].push_back(B);
    D[B].push_back(A);
    amin = max(amin, min(a, b));
    amax = max(amax, max(a, b));
  }
  sort(K.begin(), K.end());
  L = 0;
  R = K.size() + 1;
  while (R - L > 1) {
    t = (L + R) / 2;
    ke = K[t - 1].first;
    G = 1;
    for (int i = 0; i < t; i++) {
      g[K[i].second] = 1;
    }
    for (int i = t; i < k; i++) {
      g[K[i].second] = 0;
    }
    for (int i = 1; i <= k; i++) {
      S[i] = D[i].size();
    }
    for (int i = 0; i < t; i++) {
      I = K[i].second;
      if (g[I] == 1 && S[I] <= 1) {
        T.push_back(I);
        g[I] = 0;
        for (int y = 0; y < T.size(); y++) {
          for (int u = 0; u < D[T[y]].size(); u++) {
            a = D[T[y]][u];
            if (g[a] == 1) {
              S[a]--;
              if (S[a] <= 1) {
                T.push_back(a);
                g[a] = 0;
              }
            }
          }
        }
        T.clear();
      }
    }
    for (int i = 0; i < t; i++) {
      I = K[i].second;
      if (g[I] == 1) {
        T.push_back(I);
        e = 0;
        g[I] = 0;
        for (int y = 0; y < T.size(); y++) {
          e += S[T[y]];
          for (int u = 0; u < D[T[y]].size(); u++) {
            a = D[T[y]][u];
            if (g[a] == 1) {
              g[a] = 0;
              T.push_back(a);
            }
            if (N[a] > ke) {
              e++;
            }
          }
        }
        v = T.size();
        e /= 2;
        if (e > v) {
          G = 0;
          i += k;
        }
        T.clear();
      }
    }
    if (G == 1) {
      R = t;
    } else {
      L = t;
    }
  }
  if (R >= K.size() + 1) {
    cout << "-1";
  } else {
    cout << K[R - 1].first;
  }
  return 0;
}
