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

signed main(){
	int N;
	cin >> N;
	vector<int> dp(100000+5, 0);
	dp[0] = 1;
	for(int i=0;i<N;i++)
	{
		int a,b;
		cin >> a >> b;
		dp[a]++;
		dp[b+1]--;
	}
	for(int i=1;i<=100001;i++){
		dp[i] += dp[i-1];
	}
	for(int i=100001;i>=0;i--){
		if(dp[i]>=i){
			cout << i-1 << endl;
			break;
		}
	}
}
