#include <iostream>

using namespace std;

int main(){
	int n, f[100000][2];
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> f[i][0] >> f[i][1];
	}
	for (int i = n + 1; i >= 2; i--){
		int friends = 0;
		for (int j = 0; j < n; j++){
			if (f[j][0] <= i && f[j][1] >= i){
				friends++;
			}
		}
		if (friends >= i - 1){
			cout << i - 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}