#include <cstdio>
using namespace std;

const int MAX_N = int(1e5);
int N;
int dups[MAX_N + 3];

void init() {
	scanf("%d", &N);
	for (int _ = 0; _ < N; ++_) {
		int from, to;
		scanf("%d%d", &from, &to);
		++dups[from-1];
		--dups[to];
	}
}

int solve() {
	for (int i = 0; i < MAX_N + 2; ++i) {
		dups[i+1] += dups[i];
	}
	for (int i = N; i >= 0; --i) {
		if (dups[i] >= i) {
			return i;
		}
	}
	return 0;
}

int main() {
	init();
	printf("%d\n", solve());
	return 0;
}