#include<cstdio>

using namespace std;

const int MAX = 100005;
int res[MAX];

int main(){

  int n;
  scanf("%d",&n);

  while(n--){
    int a,b;
    scanf("%d %d",&a,&b);
    res[a-1]++;
    res[b]--;
  }

  int now = 0;
  int ans = 0;
  for(int i = 0; i < MAX; i++){
    now += res[i];
    if(now >= i) ans = i;
  }

  printf("%d\n",ans);
  return 0;
}