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