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) if max(p,q)>min(r,s): print(0) else: print(max(0,max(q,s)-min(r,p)+1))