#include <bits/stdc++.h>
const double EPS = 1e-10;
const double PI = acos(-1.0);
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<pair<int, int> > e;
  for (int i = (0); i < (n); ++i) {
    int a, b;
    cin >> a >> b;
    e.push_back(make_pair(a, b));
  }
  sort((e).begin(), (e).end());
  int answer = 0;
  for (int i = (0); i < (n); ++i) {
    if (answer <= e[i].second)
      answer = e[i].second;
    else
      answer = e[i].first;
  }
  cout << answer << endl;
  return 0;
}
