N=int(input()) A=[];c=10**10 for i in range(N): l,r=map(int, input().split()) A.append((l,r)) A=sorted(A,key=lambda x: x[1]) A=sorted(A,key=lambda x: x[0]) #print(A) B=[] ll=-10**10;rr=10**10 for i in range(N): l,r=A[i] ll=max(ll,l-i) rr=min(rr,r-i) p,q=ll,rr# #print(ll,rr) A=sorted(A,key=lambda x: x[0]) A=sorted(A,key=lambda x: x[1]) #print(A) ll=-10**10;rr=10**10 for i in range(N): l,r=A[i] ll=max(ll,l-i) rr=min(rr,r-i) r,s=ll,rr #print(p,q,r,s) print(max(0,s-p+1))