#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> a(100010);
	for (int i = 0; i < N; ++i) {
		int x, y;
		cin >> x >> y;
		++a[x-1];
		--a[y];
	}
	int c = 0;
	int r = 0;
	for (int i = 1; i < a.size(); ++i) {
		c += a[i];
		if (c >= i) {
			r = i;
		}
	}
	cout << r << endl;
}
