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


int main(){
    int N; cin >> N;
    int imos[100010],check[100010];
    fill(check,check+100001,0);
    int a,b;
    for(int i = 0; i < N; i++){
        cin >> a >> b;
        a--; 
        check[a]++;
        check[b]--;
    }
    imos[0] = check[0];
    for(int i = 1; i <= 100001; i++){
        imos[i] = imos[i-1]+check[i];
    }
    int ans = 0;
    for(int i = 0; i <= 100001; i++){
        if(imos[i] >= i){
            ans = max(ans,i);
        }
    }
    cout << ans << endl;
}
