#include <iostream>
using namespace std;
int n,a,b;
int member[100004];
int sum;;

int main(){
	member[1]=1;
	cin >>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		member[a]++;
		member[b+1]--;
	}
	sum=0;
	for(int i=1;i<=n;i++){
		member[i+1]+=member[i];
		if(i+1<=member[i+1])sum=i;
	}
	cout<<sum <<endl;
}