i[100012],d[100012],s,w,n,a,x,y;
main()
{
  for(w=scanf("%d",&n);a++<n;d[y]++)
      scanf("%d%d",&x,&y),i[x]++;
  for(a=2;a++<=n+1;w-=d[a])
    {
      w+=i[a];
      if(w>=a)s=a-1;

    }
  printf("%d\n",s);
  exit(0);
}