#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define rep(i,k,n) for(int (i)=(k);(i)<(n);(i)++)
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define abs(a) (a)>0 ?(a):-(a)
#define llong long long

int main(){
	int N; scanf("%d",&N);
	llong x[N+1];
	llong up[N+2],down[N+2];
	rep(i,0,N+1){
		x[i]=0;
		up[i]=0;
		down[i]=0;
	}
	up[N+2]=0; down[N+2]=0;
	rep(i,0,N){
		int a,b; scanf("%d %d",&a,&b);
		rep(j,a,b+1) x[j]++;
	}
	rep(i,0,N){
		rep(j,0,N){
			up[N-i] = up[N+1-i]+x[N-i];
			down[i+1] = down[i]+x[i+1];
		}
	}
	llong M = down[N];
	llong cnt=0;
	rep(i,0,N){
		if( down[i]*2 <= M && up[i]*2 >= M ) cnt++;
		else if( down[i]*2 >= M && up[i]*2 <= M ) cnt++;
		if( down[i]*2+1==M || down[i]*2-1==M ) cnt++;
		if( up[i]*2+1==M || up[i]*2-1==M ) cnt++;
	}
	printf("%lld",cnt);
}
