#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  scanf("%lld", &n);
  pair<long long, long long> arr[5003];
  for (__typeof(n) i = 0; i < n; i++) {
    cin >> arr[i].first >> arr[i].second;
  }
  sort(arr, arr + n);
  long long mn = 0;
  for (__typeof(n) i = 0; i < n; i++) {
    if (mn <= arr[i].second) {
      mn = arr[i].second;
    } else {
      mn = arr[i].first;
    }
  }
  cout << mn << endl;
}
