#include <stdio.h>
#include<stdlib.h>
int main() {

	int *a;
	int *b;
	int N;
	int i,k;
	int answer=0;
	int p;

	scanf("%d",&N);


	a =malloc((N+1)*sizeof(int));
	b =malloc((N+1)*sizeof(int));

	for(i=1;i<=N;i++)
		scanf("%d %d",&a[i],&b[i]);


	for(k=0;k<=N;k++) {
		p=0;
		for(i=1;i<=N;i++) {
			if(a[i]<=k&&k<=b[i])
				p++;
	    }
		if(p==k)
			answer=p-1;
	}

	printf("%d\n",answer);
	return 0;
}