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