N=int(input()) A,B=[],[] for i in range(N-1): a,b=map(int,input().split()) A.append(a) B.append(b) def check(A,B): sum_A=sum(A) sum_B=sum(B) return sum_A==sum_B and all(a+b<=sum_A for a,b in zip(A,B)) sum_A=sum(A) sum_B=sum(B) ans=0 for a in range(4*10**5): b=sum_A+a-sum_B if 0<=b and check(A+[a],B+[b]): ans+=1 print(ans)