#include <bits/stdc++.h>
using namespace std;

int A[1000010];
int N, ans;

int main() {
	cin >> N;
	for (int i = 0; i < 1000003; i++) A[i] = 0;
	for ( int n = 0; n < N; n++) {
		int a,b;
		cin >> a >> b;
		A[a] += 1;
		A[b + 1] -= 1;
	}
	ans = 0;
	for (int i = 1; i < 1000002; i++) {
		A[i] += A[i - 1];
	}
	
	for (int i = 1; i < 1000002; i++) {
		if (i <= A[i + 1]) {
			ans = i;
		}
	}
	cout << ans << endl;
}
