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