#include <iostream>
using namespace std;

int memo[100010];

int main(){
	int N;
	cin >> N;
	for(int i = 0 ; i < N ; i++){
		int a,b;
		cin >> a >> b;
		memo[a-1]++;
		memo[b]--;
	}
	int sum = 0;
	for(int i = 1 ; i <= 100001 ; i++){
		memo[i] += memo[i-1];
		//if( i < 10 ) cout << memo[i] << " ";
		
		if( i <= memo[i] ) sum = max(sum,i);
	}
	cout << sum << endl;
	
}