#include <iostream>
using namespace std;

const int MAX_N = 100010;
int s[MAX_N] = {0};

int main(){
	int n;
	cin >> n;
	for(int i=0 ; i < n ; i++ ){
		int a, b;
		cin >> a >> b;
		s[a]++, s[b+1]--;
	}
	
	for(int i=1 ; i < MAX_N ; i++ ){
		s[i] += s[i-1];
	}
	int ans = 1;
	for(int i=1 ; i < MAX_N ; i++ ){
		if( i-1 <= s[i] ) ans = i;
	}
	ans--;
	cout << ans << endl;
}