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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int N;
	cin >> N;
	
	vector< int > imos(100010, 0);
	for_(i,0,N) {
		int a, b;
		cin >> a >> b;
		imos[a-1]++;
		--imos[b];
	}
	
	for_(i,0,100010) imos[i+1] += imos[i];
		
	int ans = 0;
	for_(i,0,100010) if (i <= imos[i]) ans = i;
	cout << ans << endl;
}