N=int(input()) l=0 r=10**10 L=[] R=[] h=[] u=10**10 for i in range(N): a,b=map(int,input().split()) L.append(a-1) R.append(b-1) h.append([a-1,b-1]) u=min(u,a-1) L.sort() R.sort() for i in range(N): l=max(l,L[i]-i) for i in range(N): r=min(r,R[i]-i) if l>r: print(0) exit() ans=r-l+1 if ans>10**2: print(ans) exit() p=0 for i in range(N): h[i][0]-=u h[i][1]-=u p=max(p,h[i][0]) if p>10**7: print(ans) exit() G=[[] for i in range(p+1)] for i in range(N): x,y=h[i][:] G[x].append(y) result=0 from heapq import heappush,heappop for k in range(l-u,r-u+1): S=[] b=True for x in range(k): for y in G[x]: heappush(S,y) for i in range(N): t=i+k if t<=p: for y in G[t]: heappush(S,y) if len(S)==0: b=False break w=heappop(S) if w