#include <iostream>
using namespace std;
 
int main(void){
    int n;
    cin >> n;
    int a[101010] = {};
    int l, r;
    for (int i = 0; i < n; i++) {
        cin >> l >> r;
        a[l]++;
        a[r+1]--;
    }
    for (int i = 0; i < n+2; i++) a[i+1] += a[i];
     
    int ans = 0;
    for (int i = 2; i < n+2; i++) {
        if (a[i]+1 >= i) {
            ans = max(ans, i);
        }
    }
    if (ans) ans--;
    cout << ans << endl;
}