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