#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using namespace std; 
const int INF = 1e9;

int main(){
    int n;
    while(cin >> n){
        int diff[100010] = {};
        rep(i,n){
            int a,b;
            cin >> a >> b;
            ++diff[a-1];
            --diff[b];
        }
        int x = 0;
        int ans = 0;
        rep(i,100010){
            x += diff[i];
            if(x >= i) ans = i;
        }
        cout << ans << endl;
    }
}