#include <bits/stdc++.h>
using namespace std;
const int MX = 2000100;
vector<int> adj[MX];
int l[MX], vis[MX], a[MX], b[MX];
int vis_id;
vector<int> vec;
bool match(int i, int mid) {
  for (auto u : adj[i]) {
    if (u > mid) continue;
    if (vis[u] == vis_id) continue;
    vis[u] = vis_id;
    if (l[u] == -1 || match(l[u], mid)) {
      l[u] = i;
      return true;
    }
  }
  return false;
}
int runMatching(int n, int mid) {
  memset(l, -1, sizeof l);
  for (int i = 0; i < n; i++) {
    vis_id++;
    if (!match(i, mid)) return 0;
  }
  return 1;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    vec.push_back(a[i]);
    vec.push_back(b[i]);
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  for (int i = 0; i < n; ++i) {
    adj[i].push_back(lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin());
    adj[i].push_back(lower_bound(vec.begin(), vec.end(), b[i]) - vec.begin());
  }
  int l = n - 1, r = vec.size() - 1;
  while (l < r) {
    int mid = l + (r - l) / 2;
    if (runMatching(n, mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (!runMatching(n, r))
    cout << "-1" << endl;
  else
    cout << vec[r] << endl;
}
