#include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int N=read();
	int a[N],b[N];
	int check[100050]={0};
	REP(i,N){
		a[i]=read();
		b[i]=read();
	}
	
	REP(i,N){
		check[a[i]] += 1;
		check[b[i]+1] -=1;
	}
	
	int sum=1;
	int ans=0;
	REP(i,N+2){
		sum += check[i];
		if(sum>=i) ans=i;
	}
	cout << ans-1 << endl;
}