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