#include <iostream>
#include <vector>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int imos[100010];

int main () {
    int n;
    imos[0]++;
    imos[100002]--;
    cin >> n;
    REP (i, 0, n) {
        int a, b;
        cin >> a >> b;
        imos[a]++;
        imos[b + 1]--;
    }
    REP (i, 1, 100010) imos[i] += imos[i - 1];
    int ans = 0;

    REP (i, 0, 100010) {
        if (imos[i] >= i) ans = i;
    }
    cout << ans - 1 << endl;
    return 0;
}