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

int T[100003] = {};

int main()
{
	int N;
	cin >> N;
	REP(i, N)
	{
		int t1, t2;
		cin >> t1 >> t2;
		T[t1]++;
		T[t2+1]--;
	}
	int ans = 0;
	int temp = 1;
	REP(i, 100003)
	{
		temp += T[i];
		if(i<=temp)ans = i;
	}
	cout << ans-1 << endl;
	return 0;
}