#include <iostream>
#include <vector>

using namespace std;

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