#include <iostream>
using namespace std;

int main() {
    int n, a, b;
    int p[100002] = {};
    int res = 0;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a >> b;
        p[a]++;
        p[b+1]--;
    }
    for (int i=1; i<100002; i++) {
        p[i] += p[i-1];
    }
    res = 1;
    for (int i=1; i<100002; i++) {
        if (p[i] >= i-1) {
            res = i;
        }
    }
    res--;
    cout << res << endl;
    return 0;
}