#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000009], ck[1000009], t, in[1000009][3];
vector<int> adj[1000009], num;
bool dfs(int u) {
  if (ck[u] != t)
    ck[u] = t;
  else
    return 0;
  for (int v : adj[u])
    if (a[v] == -1) {
      a[v] = u;
      return 1;
    }
  for (int v : adj[u])
    if (dfs(a[v])) {
      a[v] = u;
      return 1;
    }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 2; j++) {
      cin >> in[i][j];
      num.push_back(in[i][j]);
    }
  sort(num.begin(), num.end());
  num.resize(unique(num.begin(), num.end()) - num.begin());
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 2; j++)
      in[i][j] =
          lower_bound(num.begin(), num.end(), in[i][j]) - num.begin() + 1;
  for (int i = 1; i <= n; i++) {
    adj[in[i][1]].push_back(i);
    adj[in[i][2]].push_back(i);
  }
  memset(a, -1, sizeof(a));
  int cnt = 0;
  for (int i = 0; i < num.size(); i++)
    if (dfs(i + 1)) {
      t++;
      cnt++;
      if (cnt == n) {
        cout << num[i];
        return 0;
      }
    }
  cout << -1;
  return 0;
}
