#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
vector<pair<int, int> > a;
int n;
bool used[N];
map<int, bool> day;
int main() {
  cin >> n;
  int pos = 0;
  for (int i = 0; (i) < (n); ++i) {
    int x, y;
    cin >> x >> y;
    a.emplace_back(x, pos);
    a.emplace_back(y, pos);
    pos++;
  }
  sort((a).begin(), (a).end());
  set<int> state, state2;
  pos = 0;
  while (state.size() < n) {
    state.insert(a[pos].second);
    state2.insert(a[pos].first);
    pos++;
  }
  while (state2.size() < n) {
    state2.insert(a[pos].first);
    pos++;
  }
  if (pos == 2 * n + 1) {
    cout << -1 << endl;
  } else {
    cout << a[pos - 1].first << endl;
  }
  return 0;
}
