#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAX = 1e6+2;

int main(){
	int n;
	cin >> n;
	
	vector<int> nf(MAX, 0);
	for(int i=0; i<n; i++){
		int a,b;
		cin >> a >> b;
		nf[a]++;
		nf[b+1]--;
	}
	
	int ans=0;
	for(int i=2; i<MAX; i++){
		nf[i] += nf[i-1];
		if(nf[i]+1>=i) ans=i-1;
	}
	cout << ans << endl;
	return 0;
}