N = int(input()) L = [[int(l) for l in input().split()] for _ in range(N-1)] A = 0 B = 0 for t in L: A += t[0] B += t[1] ans = min(A, B)+1 for i in range(N-1): if L[i][0] == A and L[i][1] > 0: ans -= 1 break if L[i][0] > 0 and L[i][1] == B: ans -= 1 break print(ans)