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