#include <cstdio>
int h[100010];

typedef unsigned int uint;
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}

int main(){
	int n = in();
	for(int i = 0 ; i < n ; i++){ int a = in() , b = in() ; h[a-1]++ , h[b]--; }
	int ans = 0 , cur = 0;
	for(int i = 0 ; i <= 100001 ; i++){
		cur += h[i];
		if(cur >= i) ans = i;
	}
	printf("%d\n",ans);
}