#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, a[N], b[N], r_val[2 * N], mark[N], rhs[2 * N], lhs[2 * N];
vector<pair<int, int> > val;
int T = 1;
vector<int> adj[2 * N];
bool dfs(int u) {
  if (mark[u] == T) return 0;
  mark[u] = T;
  for (int v : adj[u]) {
    if (rhs[v] == -1) {
      rhs[v] = u;
      return true;
    }
  }
  for (int v : adj[u]) {
    if (dfs(rhs[v])) {
      rhs[v] = u;
      return true;
    }
  }
  return false;
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i];
    val.push_back(pair<int, int>(a[i], i));
    val.push_back(pair<int, int>(b[i], i + n));
  }
  memset(rhs, -1, sizeof rhs);
  memset(lhs, -1, sizeof lhs);
  int pre = -1, id = 0;
  sort(val.begin(), val.end());
  for (int i = 0; i < val.size(); ++i) {
    if (val[i].first != pre) {
      id++;
      r_val[id] = val[i].first;
    }
    if (val[i].second <= n)
      a[val[i].second] = id;
    else
      b[val[i].second - n] = id;
    pre = val[i].first;
  }
  for (int i = 1; i <= n; ++i) {
    adj[a[i]].push_back(i);
    adj[b[i]].push_back(i);
  }
  int match = 0;
  for (int i = 1; i <= id; ++i) {
    if (dfs(i)) {
      T++;
      match++;
      if (match == n) {
        cout << r_val[i] << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
