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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

const int INF = 1<<29;

int x[100010];
int main(){
	int n;
	cin >> n;
	rep(i, n){
		int a, b;
		cin >> a >> b;
		x[a]++, x[b+1]--;
	}

	int num = 1;
	int best = 0;
	rep(i, 100010){
		num += x[i];
		if(num >= i){
			best = max(best, i-1);
		}
	}
	cout << best << endl;

	return 0;
}