#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
const long long int inf = 1e9;
const long long int MOD = 1e9 + 7;
const long long int nax = 1000000 + 10;
int minans = INF;
int n;
vector<int> v;
int arr1[nax], arr2[nax];
void solve() {
  unordered_map<int, int> map1;
  int curminans = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == 0) {
      if (map1[arr1[i + 1]] == 1) return;
      map1[arr1[i + 1]] = 1;
      curminans = max(curminans, arr1[i + 1]);
    } else {
      if (map1[arr2[i + 1]] == 1) return;
      map1[arr2[i + 1]] = 1;
      curminans = max(curminans, arr2[i + 1]);
    }
  }
  minans = min(minans, curminans);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr1[i] >> arr2[i];
  int mid = n / 2;
  int left = n - mid;
  mid *= 2;
  left *= 2;
  while (mid--) v.push_back(0);
  while (left--) v.push_back(1);
  for (int i = 1; i <= 600; i++) {
    random_shuffle(v.begin(), v.end());
    solve();
  }
  v.clear();
  mid = n / 2 + 1;
  left = n - mid;
  mid *= 2;
  left *= 2;
  while (mid--) v.push_back(0);
  while (left--) v.push_back(1);
  for (int i = 1; i <= 600; i++) {
    random_shuffle(v.begin(), v.end());
    solve();
  }
  if (minans == INF)
    cout << -1;
  else
    cout << minans << "\n";
  return 0;
}
