#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000007;
const int INF = 1e9 + 7;
int t[maxn][2];
int a[maxn * 2];
int n;
int cnt;
inline int ID(int x) { return lower_bound(a, a + cnt, x) - a; }
struct Name {
  int sz;
  map<int, int> id;
  Name() : sz(0) {}
  inline int get(int x) {
    if (!id.count(x)) id[x] = sz++;
    return id[x];
  }
};
void dfs(int u, int& vn, int& en, vector<int>& vis,
         vector<vector<int> >& edge) {
  vis[u] = 1;
  vn++;
  for (auto v : edge[u]) {
    en++;
    if (vis[v]) continue;
    dfs(v, vn, en, vis, edge);
  }
}
bool judge(int x) {
  vector<int> vist(cnt, 0);
  vector<int> agd(n, 0);
  vector<int> ex;
  for (int i = (0); i < (n); ++i) {
    if (t[i][0] > x) return false;
    if (t[i][1] > x) {
      if (vist[t[i][0]]) return false;
      vist[t[i][0]] = 1;
      continue;
    }
    ex.push_back(i);
  }
  vector<vector<int> > edge;
  Name id;
  for (auto i : ex) {
    int u, v;
    u = t[i][0], v = t[i][1];
    if (vist[u] && vist[v]) return false;
    u = id.get(u);
    if (u >= edge.size()) edge.push_back(vector<int>());
    v = id.get(v);
    if (v >= edge.size()) edge.push_back(vector<int>());
    if (vist[u])
      edge[v].push_back(v), edge[v].push_back(v);
    else if (vist[v])
      edge[u].push_back(v), edge[v].push_back(u);
    else
      edge[u].push_back(v), edge[v].push_back(u);
  }
  vector<int> vis(id.sz, 0);
  for (int i = (0); i < (id.sz); ++i) {
    if (vis[i]) continue;
    int vn, en;
    vn = en = 0;
    dfs(i, vn, en, vis, edge);
    en /= 2;
    if (en > vn) return false;
  }
  return true;
}
int main(void) {
  scanf("%d", &(n));
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (2); ++j) scanf("%d", &(t[i][j])), a[cnt++] = t[i][j];
  sort(a, a + cnt);
  cnt = unique(a, a + cnt) - a;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (2); ++j) t[i][j] = ID(t[i][j]);
  int L = 0;
  int R = cnt;
  while (L < R) {
    int mid = R - (R - L + 1) / 2;
    if (judge(mid))
      R = mid;
    else
      L = mid + 1;
  }
  if (L < cnt)
    printf("%d\n", a[L]);
  else
    puts("-1");
  return 0;
}
