#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  long long n;
  cin >> n;
  pair<long long, long long> arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first >> arr[i].second;
  }
  sort(arr, arr + n);
  int last = 0;
  for (int i = 0; i < n; i++) {
    if (last <= arr[i].second) {
      last = arr[i].second;
    } else if (last <= arr[i].first) {
      last = arr[i].first;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << last << endl;
  return 0;
}
