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

int main(){
	int n;
	cin >> n;
	vector<int> v(100010);
	for(int i = 0; i < n; ++i){
		int a, b;
		cin >> a >> b;
		v[a-1]++;
		v[b]--;
	}
	int ans = v[0];
	for(int i = 0; i <= n; ++i){
		v[i+1] += v[i];
		if(v[i+1] >= i+1) ans = i+1;
	}
	cout << ans << endl;
	return 0;
}
