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 if r>s and p>q: print(0) elif r>s: print(q-p+1) elif p>q: print(s-r+1) else: if q>=r: print(s-p+1) else: print(s-r+1+q-p+1)