#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000
using namespace std;
typedef pair<int,int> P;
int main(){
    vector<int> allow(100001,0);
    int n;
    cin >> n;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        allow[a-1]++;
        allow[b]--;
    }
    int ans;
    for(int i=0; i<=n; i++){
        if(i) allow[i] += allow[i-1];
        if(allow[i] >= i) ans = i;
    }
    cout << ans << endl;
    return 0;
}
