N = int(input()) AB = [list(map(int, input().split())) for i in range(N-1)] sa = sum(a for a, _ in AB) sb = sum(b for _, b in AB) amin, bmin = 0, 0 for i in range(N-1): a, b = AB[i] amin = max(amin, b-(sa-a)) bmin = max(bmin, a-(sb-b)) d = sa - sb ans = min(sb, sa -d) - max(amin, bmin-d) + 1 print(ans)