#include <iostream>
#include <algorithm>
using namespace std;

int N;


int main() {
    cin >> N;
    int memo[101010];
    fill(memo, memo+101010, 0);
    for (int j = 0; j < N; ++j) {
        int a, b;
        cin >> a >> b;
        ++memo[a];
        --memo[b+1];
    }
    int ret = 0;
    for (int j = 2; j < 101010; ++j) {
        memo[j] += memo[j-1];
        if (memo[j] >= j-1) {
            ret = max(ret, j-1);
        }
    }
    cout << ret << endl;
    return 0;
}