#include <bits/stdc++.h>
using namespace std;
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const int N = 1e6 + 10;
int adj[N][2];
vector<int> id;
int vis[N << 1], colAssign[N << 1], rowAssign[N];
int test_id, md, n, cols;
bool canMatch(int i) {
  for (int j : adj[i]) {
    if (j > md || vis[j] == test_id) continue;
    vis[j] = test_id;
    if (colAssign[j] == -1 || canMatch(colAssign[j])) {
      colAssign[j] = i;
      rowAssign[i] = j;
      return true;
    }
  }
  return false;
}
bool maximum_bipartite_matching() {
  for (int i = 0; i < n; i++) {
    test_id++;
    if (rowAssign[i] == -1 && !canMatch(i)) return false;
  }
  return true;
}
int main() {
  run();
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> adj[i][0] >> adj[i][1];
    id.push_back(adj[i][0]);
    id.push_back(adj[i][1]);
  }
  sort(id.begin(), id.end());
  id.resize(unique(id.begin(), id.end()) - id.begin());
  for (int i = 0; i < n; i++) {
    adj[i][0] = lower_bound(id.begin(), id.end(), adj[i][0]) - id.begin();
    adj[i][1] = lower_bound(id.begin(), id.end(), adj[i][1]) - id.begin();
  }
  cols = (int)(id.size());
  int st = n - 1, ed = (int)(id.size()) - 1, ans = -1;
  while (st <= ed) {
    md = (st + ed) >> 1;
    if (maximum_bipartite_matching()) {
      ed = md - 1, ans = md;
      memset(colAssign, -1, cols * sizeof(int));
      memset(rowAssign, -1, n * sizeof(int));
    } else
      st = md + 1;
  }
  cout << (ans == -1 ? -1 : id[ans]) << "\n";
}
