#include <bits/stdc++.h>
int main() {
  int n, a[100000], b[100000], i, j, k, cnt, max = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d %d", &a[i], &b[i]);
  for (i = 1; i <= n; i++) {
    cnt = 0;
    for (j = 0; j < n; j++)
      if (a[j] <= i + 1 && b[j] >= i + 1) cnt++;
    if (cnt >= i) max = i;
  }
  printf("%d\n", max);
}
