#include<iostream>
using namespace std;
#define IMOSU_MAX 100010

int N;
int imosu[IMOSU_MAX];
int a,b;
int ans;

int main() {
	cin>>N;
	for (int i = 0; i < N; i++) {
		cin>>a>>b;
		imosu[a]++;
		imosu[b+1]--;
	}
	imosu[0]++;
	for (int i = 1; i < IMOSU_MAX; i++) {
		imosu[i]+=imosu[i-1];
		if(i>=ans && imosu[i]>=i)ans=i;
	}
	//for(int i=0;i<10;i++)cout<<" "<<imosu[i];
	cout<<ans-1<<endl;
	//cin>>N;
	return 0;
}