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

using namespace std;

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