#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long gcd(long long a, long long b) { return (a == 0) ? b : gcd(b % a, a); }
long long cnt1(long long x) {
  long long cnt = 0;
  while (x > 0) x &= x - 1, cnt++;
  return cnt;
}
long long fact(long long n) { return n == 0 ? 1LL : n * fact(n - 1); }
long long fact(long long n, long long p) {
  return n == 0 ? 1LL : n * fact(n - 1) % p;
}
long long cnk(long long n, long long k) {
  return n == 1 || k == 1 ? 1 : cnk(n - 1, k) + cnk(n - 1, k - 1);
}
long long pow(long long a, long long n, long long p) {
  if (n == 0) return 1;
  long long t = pow(a, n / 2, p);
  return t * t * (n % 2 ? a : 1);
}
long long cnk(long long n, long long k, long long p) {
  return fact(n, p) * pow(fact(k, p), p - 2, p) * pow(fact(n - k, p), p - 2, p);
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (long long i = 0; i < v.size(); i++) is >> v[i];
  return is;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> v) {
  for (long long i = 0; i < v.size(); i++) os << v[i] << ' ';
  os << '\n';
  return os;
}
const long long N = 2e+6;
long long used[N];
long long timer = 1;
long long mt[N];
vector<long long> gr[N];
bool try_kuhn(long long v) {
  used[v] = timer;
  for (long long u : gr[v])
    if (mt[u] == -1) {
      mt[u] = v;
      return true;
    }
  for (long long u : gr[v])
    if (used[mt[u]] < timer && try_kuhn(mt[u])) {
      mt[u] = v;
      return true;
    }
  return false;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long n;
  cin >> n;
  vector<vector<long long>> ex(n, vector<long long>(2));
  vector<long long> d(2 * n);
  for (long long i = 0; i < n; i++) {
    cin >> ex[i][0] >> ex[i][1];
    d[2 * i] = ex[i][0];
    d[2 * i + 1] = ex[i][1];
  }
  sort(d.begin(), d.end());
  d.resize(unique(d.begin(), d.end()) - d.begin());
  memset(mt, -1, sizeof mt);
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < 2; j++) {
      long long t = lower_bound(d.begin(), d.end(), ex[i][j]) - d.begin();
      gr[t].push_back(i);
    }
  long long cnt = 0;
  for (long long i = 0; i < d.size(); i++)
    if (try_kuhn(i)) {
      timer++;
      cnt++;
      if (cnt == n) {
        cout << d[i];
        return 0;
      }
    }
  cout << -1;
}
