#include <bits/stdc++.h>
int main(void) {
  int N;
  int a, b;
  int count[100000] = {};
  int i, max = 0;
  scanf("%d", &N);
  while (N) {
    scanf("%d %d", &a, &b);
    for (a--; a != b; a++) {
      count[a]++;
    }
    N--;
  }
  for (i = 0; i < 100000; i++) {
    if (count[i] > i) count[i] = i;
  }
  max = count[0];
  for (i = 1; i < 100000; i++) {
    if (!count[i]) break;
    if (count[i] > max) {
      max = count[i];
    }
  }
  printf("%d\n", max);
  return 0;
}
