#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = 0;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    if (a[i].second >= ans) {
      ans = a[i].second;
    } else {
      ans = a[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}
