#include <bits/stdc++.h>
int tbl[100003];
int main() {
  int n, a, b, i, max, sum, ans;
  scanf("%d", &n);
  for (max = 0, i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    tbl[a]++, tbl[b + 1]--;
    if (b > max) max = b;
  }
  max++;
  sum = ans = 0;
  for (i = 1; i <= max; i++) {
    sum += tbl[i];
    if (sum >= i) ans = i;
  }
  if (ans > 0) ans--;
  printf("%d\n", ans);
  return 0;
}
