#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
const int MAXN = 6000;
int N;
pair<int, int> A[MAXN];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < (N); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    A[i] = {a, b};
  }
  sort(A, A + N);
  int r = 0;
  for (int i = 0; i < (N); ++i) {
    if (A[i].second >= r) {
      r = A[i].second;
    } else {
      r = A[i].first;
    }
  }
  printf("%d\n", r);
  return 0;
}
