#include <bits/stdc++.h>
using namespace std;
class dato {
 public:
  int a, b;
};
bool operator<(dato x, dato y) {
  return (x.a < y.a || (x.a == y.a && x.b < y.b));
};
dato arr[5010];
int n, v, i;
char T[40][30010], aux;
bool avanzar;
int main() {
  scanf("%ld", &n);
  for (i = 0; i < n; i++) scanf("%ld%ld", &arr[i].a, &arr[i].b);
  sort(arr, arr + n);
  v = 0;
  for (i = 0; i < n; i++)
    if (v <= arr[i].b)
      v = arr[i].b;
    else
      v = arr[i].a;
  printf("%ld\n", v);
}
