#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long

int main(void)
{
    ll n; cin>>n;
    vector<ll> v(1e7,0);
    ll ans=0;
    rep(i,n){
        ll a,b; cin>>a>>b;
        a--;
        v[a]++;
        v[b]--;
    }
    for(int i=1;i<=n;i++){
        v[i]+=v[i-1];
        if(v[i]>=i) ans=i;
    }
    cout<<ans<<endl;
    return 0;
} 
