#include <bits/stdc++.h>
using namespace std;
struct exam {
  int a, b;
} e[5005];
int cmp(const exam &x, const exam &y) {
  if (x.a != y.a) return x.a < y.a;
  return x.b < y.b;
}
int main() {
  int n, curr = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", &e[i].a, &e[i].b);
  }
  sort(e + 1, e + n + 1, cmp);
  for (int i = 1; i <= n; ++i) {
    int small, big;
    if (e[i].a < e[i].b)
      small = e[i].a, big = e[i].b;
    else
      small = e[i].b, big = e[i].a;
    if (small >= curr)
      curr = small;
    else
      curr = big;
  }
  printf("%d\n", curr);
  return 0;
}
