#include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
map<int, int> realVal, comVal;
vector<int> a[N + 5];
bool used[N + 5], ban[N + 5];
int deg[N + 5];
int maxVal;
pair<int, int> countEdges(int u) {
  used[u] = true;
  int edg = deg[u];
  int ver = 1;
  maxVal = max(u, maxVal);
  for (auto v : a[u]) {
    if (!used[v]) {
      auto res = countEdges(v);
      ver += res.first;
      edg += res.second;
    }
  }
  return {ver, edg};
}
int main() {
  int n;
  scanf("%d", &n);
  int i, u, v;
  vector<pair<int, int> > inp;
  set<int> uni;
  set<pair<int, int> > uinp;
  for (i = 0; i < n; i++) {
    scanf("%d %d", &u, &v);
    if (uinp.count({u, v}) == 0) {
      inp.push_back({u, v});
      uinp.insert({u, v});
      uni.insert(u);
      uni.insert(v);
    }
  }
  i = 1;
  for (auto it : uni) {
    comVal[it] = i;
    realVal[i] = it;
    i++;
  }
  int m = i - 1;
  for (auto it : inp) {
    u = comVal[it.first];
    v = comVal[it.second];
    deg[u]++;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  for (i = 1; i <= m; i++) {
    if (!used[i]) {
      maxVal = 0;
      auto res = countEdges(i);
      if (res.second < res.first) {
        ban[maxVal] = true;
      }
    }
  }
  vector<int> ans;
  for (i = 1; i <= m; i++) {
    if (!ban[i]) {
      ans.push_back(i);
    }
  }
  if (ans.size() < n) {
    printf("-1");
    return 0;
  }
  printf("%d", realVal[ans[n - 1]]);
  return 0;
}
