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

using namespace std;

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

	return 0;
}
