#include <bits/stdc++.h>
using namespace std;
struct test {
  int order;
  int change;
};
struct rule {
  bool operator()(const test& s1, const test& s2) {
    if (s1.order != s2.order)
      return s1.order < s2.order;
    else
      return s1.change < s2.change;
  }
};
int main() {
  int n;
  scanf("%d", &n);
  test per[5010];
  for (int i = 0; i < n; i++) scanf("%d%d", &per[i].order, &per[i].change);
  sort(per, per + n, rule());
  int day = 0;
  for (int i = 0; i < n; i++) {
    if (per[i].change >= day)
      day = per[i].change;
    else
      day = per[i].order;
  }
  printf("%d\n", day);
  return 0;
}
