#include <iostream>
using namespace std;

int main(){
	int a[100002] = {};
	int n,x,y,res = 0;
	a[1] = 1;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> x >> y;
		y++;
		a[x]++;
		a[y]--;
	}
	for(int i = 0;i < 100002;i++){
		a[i+1] += a[i];
	}
	for(int i = 0;i < 100002;i++){
		if(a[i] >= i){
			res = i;
		}
	}
	res--;
	cout << res <<endl;

	return 0;
}