#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
ll size = 100010;


int main(){
 ll n;
 cin>>n;
 ll res=0;
 vector<ll> c(size,0);
 for(ll i=0;i<n;i++){
  ll a,b;
  cin>>a>>b;
  c[a]++;
  c[b+1]--;
 }
 for(ll i=1;i<size;i++){
  c[i] += c[i-1];
 }
 for(ll i=0;i<size;i++){
  if( c[i] +1 >= i ) res = i-1;
 }
 cout<<res<<endl;

    return 0;
}

