#include<iostream>
using namespace std;


int e[100002];

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