#include <iostream>
#include <vector>
using namespace std;

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