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