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