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**20;rr=10**20 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**20;rr=10**20 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 p<=q and r<=s: print(max(q,s)-min(r,p)+1) else: print(0)