#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const int mod = 1000000007;
const int MAXN = 1e5 + 5;
const int INF = 100000000;
void read_code() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  read_code();
  int n;
  cin >> n;
  pair<int, int> arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;
  int res = 0;
  sort(arr, arr + n);
  for (long long i = 0; i < n; i++) {
    if (res = (arr[i].second >= res) ? arr[i].second : arr[i].first)
      ;
  }
  cout << res;
  return 0;
}
