#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  int a[100000], b[100000];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &a[i], &b[i]);
    a[i]--;
    b[i]--;
  }
  int left = 0, right = N;
  while (left != right) {
    int center = (left + right + 1) / 2;
    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (a[i] <= center && center <= b[i]) {
        ans++;
      }
    }
    if (ans >= center) {
      left = center;
    } else {
      right = center - 1;
    }
  }
  printf("%d\n", left);
  return (0);
}
