#include <bits/stdc++.h>
using namespace std;
int rnk[2000100], parent[2000100], nodes[2000100], edges[2000100];
void init(int n) {
  for (int i = 0; i < n; ++i) parent[i] = i, nodes[i] = 1;
}
int root(int i) { return parent[i] == i ? i : parent[i] = root(parent[i]); }
int badCnt = 0;
void merge(int a, int b) {
  a = root(a);
  b = root(b);
  if (a == b) {
    return;
  }
  if (rnk[a] > rnk[b]) swap(a, b);
  badCnt -= int(nodes[b] < edges[b]);
  badCnt -= int(nodes[a] < edges[a]);
  parent[a] = b;
  edges[b] += edges[a];
  nodes[b] += nodes[a];
  rnk[b] += rnk[a] == rnk[b];
  badCnt += int(nodes[b] < edges[b]);
}
vector<int> todo[2 * 2000100];
int firstsAt[2 * 2000100];
vector<int> ids[2 * 2000100];
bool seen[2000100];
int seenCnt;
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int> > v(n);
  vector<int> zip;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &v[i].first, &v[i].second);
    zip.push_back(v[i].first);
    zip.push_back(v[i].second);
  }
  sort(zip.begin(), zip.end());
  zip.resize(unique(zip.begin(), zip.end()) - zip.begin());
  for (int i = 0; i < n; ++i) {
    v[i].first = lower_bound(zip.begin(), zip.end(), v[i].first) - zip.begin();
    v[i].second =
        lower_bound(zip.begin(), zip.end(), v[i].second) - zip.begin();
    ids[v[i].first].push_back(i);
    ids[v[i].second].push_back(i);
    todo[v[i].second].push_back(v[i].first);
    firstsAt[v[i].first]++;
  }
  init(2 * n);
  for (int t = 0; t < 2 * n; ++t) {
    for (int i : ids[t]) {
      if (!seen[i]) {
        seen[i] = true;
        seenCnt++;
      }
    }
    int node = root(t);
    badCnt -= int(nodes[node] < edges[node]);
    edges[node] += firstsAt[t];
    badCnt += int(nodes[node] < edges[node]);
    for (int j : todo[t]) merge(j, t);
    if (seenCnt == n && badCnt == 0) {
      printf("%d\n", zip[t]);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
