#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;

int N;
int ruisekiwa[100000 + 10];

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