#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e6 + 10;
struct union_find {
  int par[MAXN], sz[MAXN];
  int diff[MAXN];
  int nposi;
  int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }
  void merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x != y) {
      if (sz[x] > sz[y]) {
        swap(x, y);
      }
      par[x] = y;
      sz[y] += sz[x];
      nposi -= (diff[x] > 0);
      nposi -= (diff[y] > 0);
      diff[y] += diff[x];
      nposi += (diff[y] > 0);
    }
  }
} uf;
int N;
int A[MAXN], B[MAXN];
int inda[MAXN], indb[MAXN];
int nleft[MAXN];
vector<int> vals;
vector<int> vleft[MAXN];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &A[i], &B[i]);
    vals.push_back(A[i]);
    vals.push_back(B[i]);
  }
  sort((vals).begin(), (vals).end());
  vals.resize(unique((vals).begin(), (vals).end()) - vals.begin());
  for (int i = 0; i < MAXN; i++) {
    uf.par[i] = i;
    uf.sz[i] = 1;
  }
  uf.nposi = N;
  for (int i = 0; i < N; i++) {
    uf.diff[i] = 1;
  }
  for (int i = 0; i < vals.size(); i++) {
    uf.diff[i + N] = -1;
  }
  for (int i = 0; i < N; i++) {
    inda[i] = lower_bound((vals).begin(), (vals).end(), A[i]) - vals.begin();
    indb[i] = lower_bound((vals).begin(), (vals).end(), B[i]) - vals.begin();
    vleft[inda[i]].push_back(i);
    vleft[indb[i]].push_back(i);
  }
  for (int i = 0; i < vals.size(); i++) {
    for (int li : vleft[i]) {
      uf.merge(li + N, i);
    }
    if (uf.nposi == 0) {
      printf("%d\n", vals[i]);
      return 0;
    }
  }
  puts("-1");
}
