#include <bits/stdc++.h>
using namespace std;
struct sub {
  int a, b;
  sub() {}
  sub(int a, int b) : a(a), b(b) {}
  bool operator<(const sub &l) const {
    if (a != l.a)
      return a < l.a;
    else
      return b < l.b;
  }
};
sub D[10005];
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d%d", &D[i].a, &D[i].b);
  }
  sort(D + 1, D + N + 1);
  int n = 1;
  for (int i = 1; i <= N; i++) {
    if (D[i].b >= n)
      n = D[i].b;
    else
      n = D[i].a;
  }
  printf("%d", n);
  return 0;
}
