#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1000 * 1000 + 11;
int n;
int a[N], b[N];
vector<int> val{0};
int t = 0;
int match[N], mk[N];
bool dfs(vector<vector<int>> &g, int u) {
  if (mk[u] == t) return false;
  mk[u] = t;
  for (int v : g[u])
    if (match[v] == -1) return match[v] = u, true;
  for (int v : g[u]) {
    if (match[v] == -1 || (dfs(g, match[v]))) {
      match[v] = u;
      return true;
    }
  }
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    val.push_back(a[i]);
    val.push_back(b[i]);
  }
  sort((val).begin(), (val).end());
  (val).resize(unique((val).begin(), (val).end()) - (val).begin());
  vector<vector<int>> g(((int)(val).size()));
  for (int i = 1; i <= n; ++i) {
    a[i] = lower_bound((val).begin(), (val).end(), a[i]) - val.begin();
    b[i] = lower_bound((val).begin(), (val).end(), b[i]) - val.begin();
    g[a[i]].push_back(i);
    g[b[i]].push_back(i);
  }
  int mt = 0;
  memset(match, -1, sizeof match);
  for (int i = 1; i < ((int)(val).size()); ++i) {
    ++t;
    if (dfs(g, i)) {
      ++mt;
      if (mt == n) {
        printf("%d\n", val[i]);
        return 0;
      }
    }
  }
  printf("-1\n");
  return 0;
}
