import sys input = sys.stdin.readline N = int(input()) A, B = [], [] for _ in range(N-1): Ai, Bi = map(int, input().split()) A.append(Ai) B.append(Bi) ans = 0 SA, SB = sum(A), sum(B) for A1 in range(SB+1): B1 = SA+A1-SB for i in range(N-1): if A[i]>B1+SB-B[i]: break else: ans += 1 print(ans)