#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a;
  long long p, q;
  for (int i = 0; i < n; i++) {
    cin >> p >> q;
    a.push_back({p, q});
  }
  sort(a.begin(), a.end());
  long long curr = a[0].second;
  for (int i = 1; i < n; i++)
    curr = (a[i].second >= curr) ? a[i].second : a[i].first;
  cout << curr << endl;
}
