#include <bits/stdc++.h>
using namespace std;
int N;
struct pr {
  int a, b;
} p[5500];
int cmp(pr p1, pr p2) {
  if (p1.a == p2.a) {
    return p1.b < p2.b;
  }
  return p1.a < p2.a;
}
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 curr = 0;
  for (int i = 1; i <= N; ++i) {
    if (p[i].a < curr) {
      curr = p[i].b;
    } else if (p[i].b < curr) {
      curr = p[i].a;
    } else {
      curr = min(p[i].a, p[i].b);
    }
  }
  printf("%d\n", curr);
  return 0;
}
