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