#include <iostream>
#include <vector>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)

const int nmax = 100005;
int imos[nmax];

int main() {
    std::ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n) {
        int a, b;
        cin >> a >> b;
        imos[a]++;
        imos[b+1]--;
    }
    for (int i = 1; i < nmax; i++)
        imos[i] += imos[i-1];
    int res;
    rep(i,nmax) {
        if (imos[i] >= i - 1)res = i - 1;
    }
    cout << res << endl;
    return 0;
}