#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000007;
const int INF = 1e9 + 7;
int t[maxn][2];
int a[maxn];
int n;
int cnt;
inline int ID(int x) { return lower_bound(a, a + cnt, x) - a; }
vector<int> Xedge[maxn * 2];
int Ymatch[maxn];
int vis[maxn];
bool dfs(int u, int co) {
  for (auto v : Xedge[u]) {
    if (vis[v] == co) continue;
    vis[v] = co;
    if (Ymatch[v] == -1 || dfs(Ymatch[v], co)) {
      Ymatch[v] = u;
      return true;
    }
  }
  return false;
}
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]), Xedge[t[i][j]].push_back(i);
  fill(Ymatch, Ymatch + maxn, -1);
  fill(vis, vis + maxn, -1);
  int has = 0;
  int ans = -1;
  for (int i = (0); i < (cnt); ++i) {
    if (dfs(i, i)) {
      has++;
      if (has == n) {
        ans = i;
        break;
      }
    }
  }
  if (~ans)
    printf("%d\n", a[ans]);
  else
    puts("-1");
  return 0;
}
