#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)



int main(void){
	//come[i] := i???(?????????????????????)??§??????????????¨?????????????????????????????????????????°
	int come[100010];

	rep(i, 100010) come[i] = 0;//0??§?????????

	int n; scanf("%d", &n);
	rep(i, n){
		int a, b;
		scanf("%d %d", &a, &b);
		reps(j, a, b + 1){
			come[j]++;
		}
	}

	
	int ans = 0;
	rep(i, 100010){
		//???????????????????????????????????????i?????§????????°??\????????????????????????
		//come[i]????????????????????§???come[i] + 1??????i???????¶????????????????????¢??????????
		if(come[i] + 1 >= i){
			//??????????????????i?????§????????°??\??????????????¨???????????¶?????????????????§???
			//???????????\???????????????????????°???i-1???
			ans = max(asn, i - 1);
		}
	}
	printf("%d\n", --ans);

	return 0;
}