#include <iostream>
using namespace std;

int main() {
    int n; cin >> n;
    int imos[101010] = {};
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        imos[a]++;
        imos[b + 1]--;
    }
    for (int i = 1; i < 101010; i++) {
        imos[i] += imos[i - 1];
    }
    for (int i = 101010 - 1; i > 0; i--) {
        if (imos[i] >= i - 1) {
            cout << i - 1 << endl;
            break;
        }
    }
}

