#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	int imos[100005]={}, a, b;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		++imos[a];
		--imos[b+1];
	}
	int cs[100005]={};
	cs[0]=imos[0];
	for (int i = 1; i < 100005; ++i)
	{
		cs[i] = cs[i-1] + imos[i];
	}

	int ans=0;
	for (int i = 2; i < 100005; ++i)
	{
		if(cs[i]+1>=i) ans = i-1;
	}
	cout << ans << endl;
	return 0;
}
