N = int(input()) AB = tuple(tuple(map(int, input().split())) for _ in range(N - 1)) a1_max = sum(b for _, b in AB) b1_max = sum(a for a, _ in AB) a1_min = max(0, a1_max - b1_max) b1_min = max(0, b1_max - a1_max) print(min(a1_max - a1_min, b1_max - b1_min) + 1)