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