#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int n, m, a[N], b[N], c[N], d[N];
int match[N];
vector<int> vc, cl, G[N];
bool vis[N];
bool dfs(int u) {
  vis[u] = 1;
  cl.push_back(u);
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i], x = match[v];
    if (!x) {
      match[v] = u;
      return 1;
    }
  }
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i], x = match[v];
    if (!vis[x] && dfs(x)) {
      match[v] = u;
      return 1;
    }
  }
  return 0;
}
void clear() {
  for (int j = 0; j < cl.size(); j++) {
    vis[cl[j]] = 0;
  }
  cl.clear();
}
int solve() {
  int k = 0;
  for (int i = 0; i < m; i++) {
    if (dfs(i)) k++;
    clear();
    if (k == n) {
      return vc[i];
    }
  }
  return -1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i], &b[i]);
    vc.push_back(a[i]);
    vc.push_back(b[i]);
  }
  sort(vc.begin(), vc.end());
  m = unique(vc.begin(), vc.end()) - vc.begin();
  vc.resize(m);
  for (int i = 1; i <= n; i++) {
    c[i] = lower_bound(vc.begin(), vc.end(), a[i]) - vc.begin();
    d[i] = lower_bound(vc.begin(), vc.end(), b[i]) - vc.begin();
    G[c[i]].push_back(i);
    G[d[i]].push_back(i);
  }
  printf("%d\n", solve());
}
