#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<long long, long long>> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first;
    cin >> arr[i].second;
  }
  sort(arr.begin(), arr.end());
  long long ctr;
  ctr = arr[0].second;
  for (int i = 1; i < n; i++) {
    if (arr[i].first >= ctr && arr[i].second >= ctr)
      ctr = arr[i].second;
    else
      ctr = arr[i].first;
  }
  cout << ctr;
}
