#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  int N;
  cin >> N;
  vector<pair<int, int> > data(N);
  for (int _n = N, i = 0; i < _n; ++i) cin >> data[i].first >> data[i].second;
  sort(data.begin(), data.end());
  int last = INT_MIN;
  for (int _n = N, i = 0; i < _n; ++i) {
    if (data[i].second >= last)
      last = data[i].second;
    else
      last = data[i].first;
  }
  cout << last;
}
