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