#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(100005, 0);
	int maxi = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
		maxi = max(maxi, b[i]);
		for (int j = a[i]; j <= b[i]; ++j) c[j]++;
	}

	int ans = 0;
	for (int i = maxi; i > 0; --i) {
		if (i - 1 <= c[i]) {
			ans = i - 1;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}
