#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  pair<int, int> ab[n];
  for (int i = 0; i < n; i++) {
    cin >> ab[i].first >> ab[i].second;
  }
  sort(ab, ab + n);
  int days = ab[0].second;
  for (int i = 1; i < n; i++) {
    if (ab[i - 1].second <= ab[i].second) {
      days = ab[i].second;
    } else {
      ab[i].second = ab[i].first;
      days = ab[i].second;
    }
  }
  cout << days << endl;
  return 0;
}
