#include <bits/stdc++.h>
using namespace std;
struct test {
  int a;
  int b;
};
bool compare(test x, test y) {
  if (x.a == y.a) return x.b < y.b;
  return x.a < y.a;
}
int main() {
  test A[5002];
  int n, x, i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> A[i].a;
    cin >> A[i].b;
  }
  sort(A, A + n, compare);
  x = A[0].b;
  for (i = 0; i < n; i++) {
    if (A[i].b >= x)
      x = A[i].b;
    else
      x = A[i].a;
  }
  cout << x << endl;
  return 0;
}
