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

int main()
{
	int N;
	cin >> N;
	vector<int> sum(100003);
	for (int i = 0, a, b; i < N; i++) {
		cin >> a >> b;
		sum[a]++;
		sum[b + 1]--;
	}
	int res = -1;
	for (int i = 1; i <= 100002; i++) {
		sum[i] += sum[i - 1];
		if (sum[i] + 1 >= i) {
			res = i;
		}
	}
	cout << res - 1 << endl;
	return 0;
}