#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

int a[200000] = {};

int main(){
	
	int N;
	
	cin >> N;
	
	for(int i = 0; i < N; i++){
		int p, q;
		cin >> p >> q;
		a[p - 1]++;
		a[q]--;
	}
	
	int count = 0;
	int ans = 0;
	
	for(int i = 0; i < 200000; i++){
		count += a[i];
		if(count >= i){
			ans = i;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}