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