#include <bits/stdc++.h>
using namespace std;
long long used[2000005];
long long match[2000005];
vector<long long> g[2000005];
long long o = 0;
long long n, m;
bool dfs(long long u) {
  used[u] = o;
  for (auto &to : g[u]) {
    if (match[to] == -1) {
      match[to] = u;
      return true;
    }
  }
  for (auto &to : g[u]) {
    if (used[match[to]] != o && dfs(match[to])) {
      match[to] = u;
      return true;
    }
  }
  return false;
}
long long a[2000005], b[2000005];
bool check(long long q) {
  for (auto &i : g) {
    i.clear();
  }
  for (long long i = 0; i < n; ++i) {
    if (a[i] <= q) {
      g[i].push_back(a[i]);
      if (b[i] <= q) {
        g[i].push_back(b[i]);
      }
    }
  }
  bool fl = false;
  fill(match, match + 2000005, -1);
  long long ans = 0;
  for (long long i = 0; i < n; ++i) {
    if (used[i] != o || !fl) {
      fl = true;
      ++o;
      ans += dfs(i);
    }
  }
  return ans == n;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<long long> x;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
    x.push_back(a[i]);
    x.push_back(b[i]);
  }
  sort(x.begin(), x.end());
  x.resize(unique(x.begin(), x.end()) - x.begin());
  for (long long i = 0; i < n; ++i) {
    a[i] = lower_bound(x.begin(), x.end(), a[i]) - x.begin() + 1;
    b[i] = lower_bound(x.begin(), x.end(), b[i]) - x.begin() + 1;
  }
  long long l = -10, r = 2000100000;
  while (r - l > 1) {
    long long mid = l + (r - l) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  if (r == 1000100000 || r > x.size()) {
    cout << -1 << '\n';
    return 0;
  }
  cout << x[r - 1] << '\n';
  return 0;
}
