#include <bits/stdc++.h>
using namespace std;
int N;
pair<int, int> dat[5002];
int C[5002];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d %d", &dat[i].first, &dat[i].second);
  sort(dat + 1, dat + N + 1);
  for (int i = 1; i <= N; i++) {
    if (C[i] != 0) continue;
    int K = dat[i].second;
    C[i] = K;
    for (int j = i + 1; j <= N; j++) {
      if (C[j] == 0 && dat[j].second < K) {
        C[j] = dat[j].first;
        K = K < C[j] ? C[j] : K;
      }
    }
  }
  int mx = -1;
  for (int i = 1; i <= N; i++) mx = mx < C[i] ? C[i] : mx;
  printf("%d\n", mx);
  return 0;
}
