#include <bits/stdc++.h>
using namespace std;
int cor = 0;
struct uftree {
  int par[2000005];
  int rank[2000005];
  int cnt[2000005];
  int siz[2000005];
  uftree() {}
  void init(int n) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
      siz[i] = 1;
    }
    memset(cnt, 0, sizeof(cnt));
  }
  void add(int x, int val) {
    int v = find(x);
    cnt[v] += val;
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (cnt[x] > siz[x]) cor--;
    if (cnt[y] > siz[y]) cor--;
    if (rank[x] < rank[y]) {
      par[x] = y;
      cnt[y] += cnt[x];
      siz[y] += siz[x];
      if (cnt[y] > siz[y]) cor++;
    } else {
      if (rank[x] == rank[y]) rank[x]++;
      par[y] = x;
      cnt[x] += cnt[y];
      siz[x] += siz[y];
      if (cnt[x] > siz[x]) cor++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
uftree uf;
int n;
int a[1000005], b[1000005];
vector<int> vi;
vector<int> vec[2000005];
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    vi.push_back(a[i]);
    vi.push_back(b[i]);
  }
  sort(vi.begin(), vi.end());
  vi.erase(unique(vi.begin(), vi.end()), vi.end());
  int mio = 0;
  uf.init(vi.size());
  pair<int, int> que;
  for (int i = 0; i < n; i++) {
    a[i] = lower_bound(vi.begin(), vi.end(), a[i]) - vi.begin();
    b[i] = lower_bound(vi.begin(), vi.end(), b[i]) - vi.begin();
    mio = max(mio, a[i]);
    vec[b[i]].push_back(a[i]);
  }
  for (int i = 0; i < n; i++) {
    uf.add(a[i], 1);
  }
  for (int i = 0; i < vi.size(); i++) {
    if (uf.cnt[i] > uf.siz[i]) {
      cor++;
    }
  }
  int r = -1;
  for (int i = 0; i < vi.size(); i++) {
    for (int j = 0; j < (int)vec[i].size(); j++) {
      uf.add(vec[i][j], -1);
      int v = uf.find(vec[i][j]);
      if (uf.cnt[v] == uf.siz[v]) {
        cor--;
      }
      uf.unite(i, vec[i][j]);
      uf.add(i, 1);
      v = uf.find(i);
      if (uf.cnt[v] == (uf.siz[v] + 1)) {
        cor++;
      }
    }
    if (cor == 0 && i >= mio) {
      r = i;
      break;
    }
  }
  if (r == -1) {
    printf("-1\n");
  } else {
    printf("%d\n", vi[r]);
  }
  return 0;
}
