#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
vector<pair<long long int, long long int> > g[N];
int a[N][2];
vector<int> s;
bool used[N], ex[N];
int n;
int cv, ce;
bool tr(int v) {
  if (used[v]) return 0;
  used[v] = 1;
  for (pair<long long int, long long int> it : g[v]) {
    int u = it.first, w = it.second;
    if (ex[w]) continue;
    if (used[u]) return 0;
    ex[w] = 1;
    if (!tr(u)) return 0;
  }
  return 1;
}
void dfs(int v) {
  ++cv;
  used[v] = 1;
  for (pair<long long int, long long int> it : g[v]) {
    int u = it.first, w = it.second;
    if (ex[w]) continue;
    ex[w] = 1;
    ++ce;
    if (!used[u]) dfs(u);
  }
}
bool chk(int k) {
  for (int i = 0; i < ((int)(s).size()); ++i) {
    used[i] = 0;
    ex[i] = 0;
  }
  for (int i = 0; i < ((int)(s).size()); ++i)
    if (i > k)
      if (!tr(i)) return 0;
  for (int i = 0; i < ((int)(s).size()); ++i) {
    if (!used[i]) {
      cv = 0;
      ce = 0;
      dfs(i);
      if (cv < ce) return 0;
    }
  }
  return 1;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  s.reserve(2 * n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 2; ++j) {
      cin >> a[i][j];
      s.push_back(a[i][j]);
    }
  }
  sort(s.begin(), s.end());
  s.resize(unique(s.begin(), s.end()) - s.begin());
  if (n > ((int)(s).size())) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 2; ++j)
      a[i][j] = lower_bound(s.begin(), s.end(), a[i][j]) - s.begin();
    g[a[i][0]].push_back({a[i][1], i});
    g[a[i][1]].push_back({a[i][0], i});
  }
  int l = 0, r = ((int)(s).size()) - 1;
  while (r - l > 1) {
    int m = (r + l) / 2;
    if (chk(m))
      r = m;
    else
      l = m;
  }
  if (chk(l))
    cout << s[l];
  else if (chk(r))
    cout << s[r];
  else
    cout << -1;
  return 0;
}
