#include<iostream>
#include<string.h>

using namespace std;

int main(){
	int n;
	cin >> n;
	
	int l[100002],r[100002];
	memset(l,0,sizeof(l));
	memset(r,0,sizeof(r));
	
	for(int i = 0;i < n;i++){
		int a,b;
		cin >> a >> b;
		l[a]++;
		r[b]++;
	}
	
	int can = 0;
	int ans = 0;
	for(int i = 1;i <= n+1;i++){
		can += l[i+1];
		if(can >= i){
			ans = i;
		}
		can -= r[i+1];
	}
	
	cout << ans << endl;
	return 0;
}
