#include <iostream>
using namespace std;
int n;
int a[100000];
int b[100000];
int count;

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