#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,s[123456]={},a,b,ans;
  cin>>n;
  while(n--){
    cin>>a>>b;
    s[a-1]++,s[b]--;
  }
  for(int i=0;i<100001;s[++i]+=s[i-1])
    if(i<=s[i])ans=i;
  cout<<ans<<endl;
  return 0;
}