#include <bits/stdc++.h>
using namespace std;
struct Arr {
  int a, b;
} p[5010];
bool cmp(Arr x, Arr y) { return x.a != y.a ? x.a < y.a : x.b < y.b; }
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &p[i].a, &p[i].b);
  sort(p + 1, p + n + 1, cmp);
  int c = p[1].b;
  for (int i = 2; i <= n; ++i) {
    c = p[i].b >= c ? p[i].b : p[i].a;
  }
  printf("%d\n", c);
  return 0;
}
