#include <iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int imos[100010];

int main(void){
	int n;
	cin >> n;
	imos[0]++;
	rep(i,n){
		int a,b;
		cin >> a >> b;
		imos[a]++,imos[b+1]--;
	}
	rep(i,n+5) imos[i+1]+=imos[i];
	int ans=0;
	rep(i,n+5) if(i<=imos[i]) ans=i;
	cout << ans-1 << endl;
	return 0;
}