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

int main() {
    int N;
    cin >> N;
    vector<int> v(100002, 0);
    int a, b;
    for (int i=0; i<N; ++i) {
        cin >> a >> b;
        v[a] ++;
        v[b+1] --;
    }
    int mx = 0;
    for (int i=1; i<=N+1; ++i) {
        v[i] += v[i-1];
        if (v[i]+1 >= i) {
            mx = max(mx, i-1);
        }
    }
    cout << mx << endl;
    return 0;
}
