#include <bits/stdc++.h>
using namespace std;
struct ww {
  int x, y;
} a[5010];
int i, j, k, n, m, Last;
inline bool cc1(const ww &a, const ww &b) {
  return a.x < b.x || a.x == b.x && a.y < b.y;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + n + 1, cc1);
  Last = 0;
  for (i = 1; i <= n; i = j) {
    for (j = i; j <= n && a[j].x == a[i].x; j++)
      ;
    if (a[i].y >= Last)
      Last = a[j - 1].y;
    else
      Last = a[i].x;
  }
  printf("%d\n", Last);
  return 0;
}
