#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef pair<int,int> P;

int n;
int a[100000], b[100000];
int x[200000];

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