#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;

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

int main(void) {
    int n; cin >> n;
    vector<int> a(150000);
    rep(i, n) {
        int l, r; cin >> l >> r;
        l--;
        a[l]++;
        a[r]--;
    }
    rep(i, a.size()-1) {
        a[i+1] += a[i];
    }
    int ret = 0;
    rep(i, a.size()) {
        if (a[i] >= i) 
            ret = i;
    }
    cout << ret << endl;
    return 0;
}

