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

int main()
{
    int n;
    cin >> n;
    int imos[100010] = {};
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        ++imos[a];
        --imos[b + 1];
    }
    int ans;
    int a = 0;
    for (int i = 0; i < 100010; ++i) {
        a += imos[i];
        if (a + 1 >= i) {
            ans = i - 1;
        }
    }
    cout << ans << "\n";
    return 0;
}