#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin >> n;
	int sum[100010] = {};
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		sum[a - 1]++;
		sum[b]--;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		sum[i] += sum[i - 1];
	}
	for (int i = 0; i <= n; i++) {
		if (sum[i] >= i) {
			ans = i;
		}
	}
	cout << ans << endl;
	return	0;
}



