#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<pair<long long, long long> > a;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long cur, cur1;
    cin >> cur >> cur1;
    a.push_back(make_pair(cur, cur1));
  }
  sort(a.begin(), a.end());
  long long cur = a[0].second;
  for (int i = 1; i < a.size(); i++) {
    if (a[i].second >= cur) {
      cur = a[i].second;
    } else {
      cur = a[i].first;
    }
  }
  cout << cur;
  return 0;
}
