#include<iostream>
using namespace std;
int main() {
	int n; cin >> n;
	int min[114514], max[114514];
	for (int i = 0; i < n; i++) {
		cin >> min[i] >> max[i];
	}
	for (int i = n + 1; i >= 1; i--) {
		int cnt = 0;
		for (int j = 0; j < n; j++) {
			if (min[j] <= i&&i <= max[j])cnt++;
		}
		if (cnt >= i - 1) {
			cout << i - 1 << endl;
			return 0;
		}
	}
	cout << "0\n";
	return 0;
}