#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define INF (1<<28)
#define N (1<<17)

int h[100010];
int main(){
	int n; cin >> n;
	
	for(int i = 0 ; i < n ; i++){
		int a,b;
		cin >> a >> b;
		a--,b--;
		h[a]++;
		h[b+1]--;
	}
	int ans = 0 , cur = 0;
	for(int i = 0 ; i <= 100001 ; i++){
		cur += h[i];
		//if(cur) cout << i << " " << cur << endl;
		if(cur >= i) ans = max(ans,i);
	}
	cout << ans << endl;
	
}