#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;


int main()
{
	int n,max=0;
	pair<int,int> a[110000];
	int v[110000]={};
	
	cin >> n;
	
	
	for(int i=0;i<n;i++){
		cin >> a[i].first >> a[i].second;
	}
	
	for(int i=0;i<n;i++){
		v[a[i].first]++;
		v[a[i].second+1]--;
	}
	v[0]++;
	for(int i=1;i<n+2;i++){
		v[i] = v[i]+v[i-1];
		if(v[i] >= i)max = i;
	}
	
	cout << max-1 << endl;
	
	
	
	return 0;
}
