#include <bits/stdc++.h>
using namespace std;
mt19937 parsa(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 2 * 1000 * 1000 + 17;
int n, a[MAXN], b[MAXN], down[MAXN], up[MAXN];
bool mark[MAXN];
vector<int> all;
void compress() {
  sort(all.begin(), all.end());
  all.resize(unique(all.begin(), all.end()) - all.begin());
  for (int i = 1; i <= n; i++)
    a[i] = lower_bound(all.begin(), all.end(), a[i]) - all.begin() + 1,
    b[i] = lower_bound(all.begin(), all.end(), b[i]) - all.begin() + 1;
}
bool dfs(int v, int x) {
  mark[v] = true;
  for (auto i : {a[v], b[v]}) {
    if (i > x) continue;
    if (!up[i] || (!mark[up[i]] && dfs(up[i], x))) {
      down[v] = i;
      up[i] = v;
      return true;
    }
  }
  return false;
}
bool find_match(int x) {
  for (int i = 1; i <= n; i++)
    if (a[i] > x && b[i] > x) return false;
  memset(down, 0, sizeof down);
  memset(up, 0, sizeof up);
  int sz = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] <= x && b[i] > x) down[i] = a[i], up[a[i]] = i, sz++;
  bool done = false;
  while (!done) {
    done = true;
    memset(mark, 0, sizeof mark);
    for (int i = 1; i <= n; i++)
      if (!down[i] && dfs(i, x)) done = false, sz++;
    if (sz == n) break;
  }
  return (sz == n);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i] >> b[i], all.push_back(a[i]), all.push_back(b[i]);
  compress();
  if (!find_match(all.size())) return cout << -1 << endl, 0;
  int l = n - 2, r = all.size() - 1;
  while (l + 1 < r) {
    int mid = l + r >> 1;
    if (find_match(mid + 1))
      r = mid;
    else
      l = mid;
  }
  cout << all[r] << endl;
  return 0;
}
