#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
long long Qpower(long long x, long long p, long long m) {
  long long r = 1;
  while (p) {
    if (p & 1) r = r * x % m;
    x = x * x % m;
    p >>= 1;
  }
  return r;
}
long long gcd(long long a, long long b) {
  while (a) {
    long long t = b % a;
    b = a, a = t;
  }
  return b;
}
map<int, int> ID;
vector<pair<int, int> > v;
int l[maxn], r[maxn], val[maxn];
int f[3 * maxn], cnt[2][3 * maxn];
int n, ans;
int Find(int x) { return f[x] == x ? x : f[x] = Find(f[x]); }
int Solve() {
  int tmp = 0;
  for (auto &it : ID) {
    it.second = ++tmp;
    val[tmp] = it.first;
  }
  for (int i = 1; i <= n; ++i) {
    l[i] = ID[l[i]], r[i] = ID[r[i]];
    v.push_back(pair<int, int>(l[i], i));
    v.push_back(pair<int, int>(r[i], i));
  }
  sort(v.begin(), v.end());
  for (int i = 1; i <= n; ++i) f[i] = i, cnt[0][i] = 1, cnt[1][i] = 0;
  for (int i = 1; i <= tmp; ++i)
    f[n + i] = n + i, cnt[0][n + i] = 0, cnt[1][n + i] = 1;
  for (int i = 0, tot = 0; i < (int)v.size(); ++i) {
    int p = Find(v[i].first + n), q = Find(v[i].second);
    if (p != q) {
      f[p] = q;
      if (cnt[0][p] <= cnt[1][p]) tot -= cnt[0][p];
      if (cnt[0][q] <= cnt[1][q]) tot -= cnt[0][q];
      cnt[0][q] += cnt[0][p];
      cnt[1][q] += cnt[1][p];
      if (cnt[0][q] <= cnt[1][q]) tot += cnt[0][q];
      if (tot == n) {
        return val[v[i].first];
      }
    }
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> l[i] >> r[i];
    ID[l[i]] = ID[r[i]] = 0;
  }
  ans = Solve();
  cout << ans << '\n';
  return 0;
}
