#include<iostream>
#include<vector>
using namespace std;
#define MAX 100005
int main(){
    int n;
    cin >> n;
    vector<int> imos(MAX);
    imos[0]++;
    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        imos[a]++;
        imos[b+1]--;
    }
    for(int i = 0; i < MAX-1; i++)imos[i+1] += imos[i];
    for(int i = MAX-1; i > 0; i--){
        if(imos[i] >= i){
            cout << i-1 << endl;
            return 0;
        }
    }

}

