#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;

int c[100003];

int main() {

    int n;
    cin >> n;

    rep(i, n) {
        int a, b;
        cin >> a >> b;
        c[a]++;
        c[b+1]--;
    }

    int ans=0, t=1;
    rep(i, 100003) {
        t += c[i];
        if (i <= t) {
            ans = i;
        }
    }

    cout << ans-1 << endl;
}