#include "bits/stdc++.h"
using namespace std;
int people[100010];
int main() {
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		int a,b;
		scanf("%d %d",&a,&b);
		people[a]++;
		people[b+1]--;
	}
	for(int i=1;i<=N+1;i++) {
		people[i]+=people[i-1];
	}
	int ans=0;
	for(int i=N;i>=0;i--) {
		if(people[i+1]>=i) {ans=i;break;}
	}
	printf("%d\n",ans);
}