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

int f[100005];

int main() {

    int n;
    int a, b;
    cin >> n;

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

    int sum=1;
    int ans=0;
    rep(i, 100005) {
        sum += f[i];
        if (i <= sum) {
            ans=i;
        }
    }

    cout << ans-1 << endl;
}