#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0;i < n;i++)
#define all(n) n.begin(),n.end()

const int INF = 1e9;

signed main() {
	int n;
	cin >> n;

	vector<int> imos(100003, 0);
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		imos[a]++;
		imos[b+1]--;
	}
	int ans = 0;
	int count = 0;
	rep(i, imos.size()) {
		count += imos[i];
		if (count >= i) {
			ans = max(i, ans);
		}
	}
	cout << ans << endl;

	return 0;
}