N=int(input()) S=[tuple(map(int,input().split())) for i in range(N-1)] MAX=0 MIN=0 for x,y in S: MAX+=y MIN+=y-x print(max(0,MAX-max(MIN,0)+1))