#include <bits/stdc++.h>
using namespace std;
int N, A, B;
pair<int, int> ex[5001];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A >> B;
    ex[i] = make_pair(A, B);
  }
  sort(ex, ex + N);
  int prevMax = min(ex[0].first, ex[0].second);
  int curMark = ex[0].first;
  for (int i = 1; i < N; i++) {
    if (curMark == ex[i].first) {
      prevMax = max(prevMax, ex[i].second);
    } else {
      if (prevMax <= ex[i].second) {
        prevMax = max(prevMax, ex[i].second);
      } else {
        prevMax = max(prevMax, ex[i].first);
      }
      curMark = ex[i].first;
    }
  }
  printf("%d\n", prevMax);
  return 0;
}
