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