The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.

If $x$ is the number of passengers in a bus just before the current bus stop and $y$ is the number of passengers in the bus just after current bus stop, the system records the number $y-x$. So the system records show how number of passengers changed.

The test run was made for single bus and $n$ bus stops. Thus, the system recorded the sequence of integers $a_1, a_2, \dots, a_n$ (exactly one number for each bus stop), where $a_i$ is the record for the bus stop $i$. The bus stops are numbered from $1$ to $n$ in chronological order.

Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $w$ (that is, at any time in the bus there should be from $0$ to $w$ passengers inclusive).


-----Input-----

The first line contains two integers $n$ and $w$ $(1 \le n \le 1\,000, 1 \le w \le 10^{9})$ — the number of bus stops and the capacity of the bus.

The second line contains a sequence $a_1, a_2, \dots, a_n$ $(-10^{6} \le a_i \le 10^{6})$, where $a_i$ equals to the number, which has been recorded by the video system after the $i$-th bus stop.


-----Output-----

Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $w$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.


-----Examples-----
Input
3 5
2 1 -3

Output
3

Input
2 4
-1 1

Output
4

Input
4 10
2 4 1 2

Output
2



-----Note-----

In the first example initially in the bus could be $0$, $1$ or $2$ passengers.

In the second example initially in the bus could be $1$, $2$, $3$ or $4$ passengers.

In the third example initially in the bus could be $0$ or $1$ passenger.

Source: codeforces | Difficulty: MEDIUM
Tags: Combinatorics

Mathematics


Solutions:
import sys
import math
import collections
import bisect

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	(n, k) = get_ints()
	arr = get_list()
	minim = 10 ** 10
	ans = 0
	maxim = -10 ** 10
	for i in arr:
		ans += i
		maxim = max(ans, maxim)
		minim = min(minim, ans)
	if maxim > k:
		print(0)
		continue
	if minim < 0:
		starting = -minim
	else:
		starting = 0
	if maxim <= 0:
		end = k
	else:
		end = k - maxim
	if starting > end:
		print(0)
	else:
		print(end - starting + 1)


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil, pi
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919]

def primef(n, plst=[]):
	if n == 1:
		return plst
	else:
		for m in primes:
			if n % m == 0:
				return primef(n // m, plst + [m])
		return primef(1, plst + [n])

def lmii():
	return list(map(int, input().split()))

def ii():
	return int(input())

def countOverlapping(string, sub):
	count = start = 0
	while True:
		start = string.find(sub, start) + 1
		if start > 0:
			count += 1
		else:
			return count
from copy import deepcopy
(n, w) = lmii()
nums = lmii()
ans = True
tot = 0
mi = 0
ma = 0
for i in nums:
	tot += i
	if tot > w:
		ans = False
	mi = min(tot, mi)
	ma = max(tot, ma)
if ans:
	ma = min(w, ma)
	check = w - ma - abs(mi) + 1
	print(max(check, 0))
else:
	print(0)


(n, w) = [int(k) for k in input().split()]
a = [int(k) for k in input().split()]
(mx, mn, sum) = (0, 0, 0)
for i in range(n):
	sum += a[i]
	mx = max(mx, sum)
	mn = min(mn, sum)
print(max(0, w - mx + mn + 1))


import sys

def main():
	d_sum = 0
	max_sum = 0
	min_sum = 0
	(n, max_weight) = map(int, input().strip().split(' '))
	diffs = [int(diff) for diff in input().strip().split(' ')]
	for diff in diffs:
		d_sum += diff
		max_sum = max(max_sum, d_sum)
		min_sum = min(min_sum, d_sum)
	if abs(min_sum) > max_weight or max_sum > max_weight:
		return print(0)
	res = max_weight - (max_sum - min_sum) + 1
	if res < 0:
		return print(0)
	print(res)
sys.exit(main())


import math
import bisect
n = list(map(int, input().split(' ')))
m = list(map(int, input().split(' ')))
init_range = [0]
final_range = [n[1]]
count = 0
for i in range(len(m)):
	count += m[i]
	init_range.append(0 - count)
	final_range.append(n[1] - count)
x = max(init_range)
y = min(final_range)
ans = y - x + 1
if ans < 0:
	ans = 0
print(ans)


a = list(map(int, input().split()))
l = list(map(int, input().split()))
m = a[1]
n = 0
su = 0
c = 0
for i in range(a[0]):
	if l[i] >= 0:
		su = su + l[i]
		if su >= 0:
			ma = a[1] - su
			if ma < m:
				m = ma
	else:
		su = su + l[i]
		if su < 0:
			mi = abs(su)
			if mi > n:
				n = mi
if n <= a[1] and m >= n:
	print(m - n + 1)
else:
	print(0)


def main():
	(_, W) = (int(i) for i in input().split())
	A = [int(i) for i in input().split()]
	from itertools import accumulate
	S = list(accumulate(A))
	ma = min(W, W - max(S))
	mi = max(0, 0 - min(S))
	ans = ma - mi + 1
	if ma < mi:
		ans = 0
	print(ans)
main()


(n, w) = map(int, input().split())
a = [int(x) for x in input().split()]
dp = [[0, 0, 0, 0] for i in range(n)]
if a[0] < 0:
	dp[0][0] = w
	dp[0][1] = w + a[0]
	dp[0][2] = -a[0]
	dp[0][3] = 0
else:
	dp[0][0] = w - a[0]
	dp[0][1] = w
	dp[0][2] = 0
	dp[0][3] = a[0]
flag = 0
for i in range(1, n):
	dp[i][1] = dp[i - 1][1] + a[i]
	dp[i][2] = dp[i - 1][2]
	dp[i][3] = dp[i - 1][3] + a[i]
	if dp[i][3] < 0:
		dp[i][2] -= dp[i][3]
		dp[i][3] = 0
	if dp[i][1] < 0:
		flag = 1
		break
	dp[i][0] = dp[i - 1][0]
	if dp[i][1] > w:
		f = dp[i][1] - w
		if dp[i][0] - f < 0:
			flag = 1
			break
		dp[i][0] -= f
		dp[i][1] = w
	if dp[i][2] > dp[i][0] or dp[i][2] > w:
		flag = 1
		break
ans = dp[n - 1][0] - dp[n - 1][2] + 1
print(ans if flag == 0 else 0)


(n, k) = map(int, input().split())
list1 = list(map(int, input().split()))
s1 = 0
s2 = k
ss1 = 0
ss2 = 0
s = 0
f = 0
for i in range(n):
	if list1[i] > k or list1[i] < -k:
		f = 1
	s += list1[i]
	if s > k or s < -k:
		f = 1
	if s < 0:
		s1 = max(s1, abs(s))
	else:
		s2 = min(s2, k - s)
if s1 <= s2 and f == 0:
	print(s2 - s1 + 1)
else:
	print(0)


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
(Max, Min) = (-4294967295, 4294967295)
bus = 0
for i in a:
	bus += i
	Max = max(Max, bus)
	Min = min(Min, bus)
busMin = max(0, -Min)
busMax = min(m, m - Max)
if busMax < busMin:
	print(0)
else:
	print(busMax - busMin + 1)


(n, w) = map(int, input().split())
(s, mx, my) = (0, 0, 0)
for i in list(map(int, input().split())):
	s += i
	mx = min(mx, s)
	my = max(my, s)
ans = w - my + mx + 1
print(max(0, ans))


def read_nums():
	return [int(x) for x in input().split()]

def main():
	(n_stops, capacity) = read_nums()
	records = read_nums()
	running_sum = 0
	running_sums = []
	for rec in records:
		running_sum += rec
		running_sums.append(running_sum)
	(max_sum, min_sum) = (max(running_sums), min(running_sums))
	max_start = capacity - max(0, max_sum)
	min_start = max(0, -min_sum)
	if min_start > max_start or max_start < 0:
		print(0)
	else:
		print(max_start - min_start + 1)
main()


(n, w) = map(int, input().split())
l = list(map(int, input().split()))
a = 0
b = w
i = 0
c = 0
while i < n:
	while l[i] >= 0:
		c += l[i]
		i += 1
		b = min(b, w - c)
		if i == n:
			break
	if i == n:
		break
	while l[i] < 0:
		c += l[i]
		i += 1
		a = max(a, -c)
		if i == n:
			break
print(max(0, b - a + 1))


(n, w) = input().split()
(n, w) = (int(n), int(w))
A = list(map(int, input().split()))
S = [0] * len(A)
s = 0
for i in range(len(A)):
	s += A[i]
	S[i] = s
if w >= abs(max(S)) and w >= abs(min(S)):
	if max(S) <= 0:
		up = w
	else:
		up = w - max(S)
	if min(S) >= 0:
		down = 0
	else:
		down = abs(min(S))
	if up - down < 0 or abs(min(S) - max(S)) > w:
		print('0')
	else:
		print(up - down + 1)
else:
	print('0')


import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline
MOD = 1000000007
PI = 3.141592653589793
I = lambda : int(input())
S = lambda : input()
M = lambda : map(int, input().split())
Ms = lambda : map(str, input().split())
ARR = lambda : list(map(int, input().split()))

def solve():
	(n, capacity) = M()
	ar = ARR()
	(mx, mn) = (capacity, 0)
	pref = 0
	for i in range(n):
		if ar[i] < 0:
			pref += abs(ar[i])
		elif ar[i] - pref > 0:
			mx -= ar[i] - pref
			pref = 0
		else:
			pref -= ar[i]
	pref = 0
	for i in range(n):
		if ar[i] > 0:
			pref += ar[i]
		elif pref < abs(ar[i]):
			mn += abs(ar[i]) - pref
			pref = 0
		else:
			pref -= abs(ar[i])
	if mx - mn + 1 <= 0:
		print(0)
	else:
		print(mx - mn + 1)
tc = 1
for _ in range(tc):
	solve()


(numstops, seats) = [int(i) for i in input().split(' ')]
stops = [int(i) for i in input().split(' ')]
runningTotal = [0]
for i in range(numstops):
	runningTotal.append(runningTotal[-1] + stops[i])
if min(runningTotal) < 0:
	minPoss = -min(runningTotal)
else:
	minPoss = 0
maxPoss = seats - max(runningTotal)
if minPoss > maxPoss or maxPoss > seats:
	print(0)
else:
	print(maxPoss - minPoss + 1)


import traceback
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
from collections import defaultdict as dfd, Counter
from functools import lru_cache
from itertools import accumulate

def geti():
	return int(input())

def gets():
	return input()

def getil():
	return list(map(int, input().split()))

def getsl():
	return input().split()

def getinps(s):
	inps = s.split()
	m = {'i': geti, 's': gets, 'il': getil, 'sl': getsl}
	if len(inps) == 1:
		return m[s]()
	return [m[k]() for k in inps]

def get2d(nrows, ncols, n=0):
	return [[n] * ncols for r in range(nrows)]

def get_acc(a):
	return list(accumulate(a))

def get_ncr(n, r):
	if n < r:
		return 0
	return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

def get_nc2(n):
	return n * (n - 1) // 2

def get_npr(n, r):
	if n < r:
		return 0
	return math.factorial(n) // math.factorial(r)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
	((N, w), a) = getinps('il il')
	(minn, maxx) = (w, 0)
	acc = get_acc(a)
	(mn, mx) = (min(acc), max(acc))
	if mn >= 0:
		mn = 0
	else:
		mn = -mn
	if mx < 0:
		mx = w
	else:
		mx = w - mx
	if mn < 0 or mx > w or mn > mx:
		return 0
	return mx - mn + 1
try:
	ans = main()
	print(ans)
except Exception as e:
	print(e)
	traceback.print_exc()


(n, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
(l, p, q) = (0, 0, 0)
for i in range(n):
	l += a[i]
	if l > 0:
		if p < l:
			p = l
	if l < 0:
		if q > l:
			q = l
(l, r) = (w - p, -q)
if l < r:
	print(0)
else:
	print(l - r + 1)


(n, w) = map(int, input().split())
ary = list(map(int, input().split()))
Min = 1000000000.0
Max = -1000000000.0
tmp = 0
for x in ary:
	tmp += x
	Min = min(Min, tmp)
	Max = max(Max, tmp)
l = max(0, 0 - Min)
r = min(w, w - Max)
print(max(0, r - l + 1))


import sys
(_, max_capacity) = list(map(int, next(sys.stdin).rstrip().split()))
xs = list(map(int, next(sys.stdin).rstrip().split()))
current = 0
max_x = 0
min_x = 0
for x in xs:
	current += x
	max_x = max(max_x, current)
	min_x = min(min_x, current)
calibration = max_x - min_x
if calibration > max_capacity:
	print(0)
else:
	print(max_capacity - calibration + 1)


(n, w) = list(map(int, input().split()))
l = list(map(int, input().split()))
ma = 0
mi = 0
p = 0
for x in l:
	p += x
	ma = max(ma, p)
	mi = min(mi, p)
re = w - ma + mi + 1
if ma == 0 and mi == 0:
	print(w + 1)
elif re < 0 or re > w:
	print(0)
else:
	print(re)


(n, w) = [int(e) for e in input().split(' ')]
line = [int(e) for e in input().split(' ')]
ma = 0
mi = 0
current = 0
for e in line:
	current += e
	ma = max(ma, current)
	mi = min(mi, current)
if w - (ma - mi) < 0:
	print(0)
else:
	print(w - (ma - mi) + 1)


(n, w) = [int(x) for x in input().split(' ')]
z = [int(x) for x in input().split(' ')]
(s, a, b) = (0, 0, 0)
for x in z:
	s += x
	a = max(a, s)
	b = min(b, s)
ans = w - a + 1 + b
if ans < 0:
	ans = 0
print(ans)


(n, w) = list(map(int, input().split()))
l = list(map(int, input().split()))
mus = [0] * n
mus[0] = l[0]
for i in range(1, n):
	mus[i] = mus[i - 1] + l[i]
if max(mus) >= 0:
	if min(mus) >= 0:
		print(max(0, w + 1 - max(mus)))
	else:
		print(max(0, w + 1 - max(mus) + min(mus)))
else:
	print(max(0, w + 1 - abs(min(mus))))


(n, w) = map(int, input().split())
l = [int(x) for x in input().split()]
m = 0
M = 0
count = 0
for item in l:
	count += item
	m = min(m, count)
	M = max(M, count)
d = M - m
if d > w:
	print(0)
else:
	print(w - d + 1)


f = lambda : map(int, input().split())
(n, w) = f()
s = a = b = 0
for q in f():
	s += q
	(a, b) = (min(s, a), max(s, b))
print(max(0, 1 + w - b + a))


(n, w) = map(int, input().split())
(sex, lu, ha) = (0, 0, 0)
for a in input().split():
	sex += int(a)
	lu = min(lu, sex)
	ha = max(ha, sex)
print(max(w - ha + lu + 1, 0))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
tmp = 0
m = 0
M = 0
for x in a:
	tmp += x
	if tmp < m:
		m = tmp
	if tmp > M:
		M = tmp
ans = w - M + m + 1
if 0 <= ans <= w + 1:
	print(ans)
else:
	print(0)


(n, w) = map(int, input().split())
L = list(map(int, input().split()))
maxx = 0
minn = 0
x = 0
for i in L:
	x += i
	maxx = max(maxx, x)
	minn = min(minn, x)
print(max(0, w + minn - maxx + 1))


from itertools import accumulate

def main():
	(n, w) = [int(_) for _ in input().split()]
	a = [int(_) for _ in input().split()]
	c = list(accumulate(a))
	ans = min(w, w - max(c)) - max(-min(c), 0) + 1
	if ans <= 0:
		print(0)
	else:
		print(ans)

def __starting_point():
	main()
__starting_point()


import sys
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def solve():
	(n, w) = li()
	arr = li()
	(minima, maxima) = (0, 0)
	sum = 0
	for i in arr:
		sum += i
		minima = min(minima, sum)
		maxima = max(maxima, sum)
	return max(w - maxima - abs(minima) + 1, 0)
print(solve())


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
k = 0
ma = 0
mi = 0
for i in a:
	k += i
	ma = max(ma, k)
	mi = min(mi, k)
u = w - ma
d = 0 - mi
p = u - d + 1
print(max(0, p))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
mx = 0
mn = 0
s = 0
for i in range(n):
	s += a[i]
	mx = max(mx, s)
	mn = min(mn, s)
print(max(w - (mx - mn) + 1, 0))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
sumtillnow = 0
maxi = 0
mini = 0
for i in a:
	sumtillnow += i
	maxi = max(maxi, sumtillnow)
	mini = min(mini, sumtillnow)
print(max(w - maxi + mini + 1, 0))


(n, w) = map(int, input().split())
cr = mx = mn = 0
for v in map(int, input().split()):
	cr += v
	mn = min(mn, cr)
	mx = max(mx, cr)
print(max(0, w - mx + mn + 1))


(n, w) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
minx = 0
maxx = w
if a[0] >= 0:
	maxx = w - a[0]
else:
	minx = -a[0]
delta = a[0]
dell = [delta]
for i in a[1:]:
	delta += i
	dell.append(delta)
	if delta > w or delta < -w:
		maxx = -5
		minx = 0
		break
	if delta + maxx > w:
		maxx -= delta + maxx - w
	elif minx + delta < 0:
		minx -= minx + delta
print(max(maxx - minx + 1, 0))


((n, w), a) = (map(int, input().split()), list(map(int, input().split())))
(l, r) = (-1, w + 1)
while r - l > 1:
	m = (r + l) // 2
	now = m + 1 - 1
	can = True
	for i in range(n):
		now += a[i]
		can &= now >= 0
	if not can:
		l = m
	else:
		r = m
if r <= 0:
	if r < 0:
		print(0)
		exit(0)
	else:
		now = 0
		if sum(a) > w:
			print(0)
			exit(0)
min_can = r
(l, r) = (0, w + 1)
while r - l > 1:
	m = (r + l) // 2
	can = True
	now = m + 1 - 1
	for i in range(n):
		now += a[i]
		can &= now <= w
	if not can:
		r = m
	else:
		l = m
max_can = max(l, 0)
print(max(max_can - min_can + 1, 0))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
if a[n - 1] < 0:
	lastMax = w - a[n - 1]
else:
	lastMax = w
for i in reversed(range(n)):
	lastMax -= a[i]
	lastMax = min(w, lastMax)
if a[n - 1] > 0:
	lastMin = a[n - 1]
else:
	lastMin = 0
for i in reversed(range(n)):
	lastMin -= a[i]
	lastMin = max(0, lastMin)
if lastMax - lastMin < 0:
	print(0)
else:
	print(lastMax - lastMin + 1)


def solve(w, arr):
	diff = 0
	(lb, ub) = (float('inf'), -float('inf'))
	for i in arr:
		diff += i
		ub = max(ub, diff)
		lb = min(lb, diff)
	return max(0, w - max(0, ub) - max(0, -lb) + 1)

def main():
	(_, w) = map(int, input().strip().split())
	arr = [int(x) for x in input().strip().split()]
	result = solve(w, arr)
	print(result)
main()


(n, w) = map(int, input().split(' '))
s = list(map(int, input().split(' ')))
sums = Max = Min = 0
for val in s:
	sums += val
	Max = max(sums, Max)
	Min = min(sums, Min)
if Max > w:
	print(0)
else:
	print(len(range(-Min, w - Max + 1)))


(n, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
s = 0
min_s = 10000000
max_s = -10000000
for (i, e) in enumerate(a):
	s += e
	min_s = min(s, min_s)
	max_s = max(s, max_s)
if -min_s > w:
	print(0)
	quit()
if max_s > w:
	print(0)
	quit()
if max_s >= 0 and min_s >= 0:
	max_s = w - max_s + 1
elif max_s >= 0 and min_s < 0:
	max_s = w - max_s + min_s + 1
elif max_s < 0:
	max_s = w + min_s + 1
if max_s < 0:
	print(0)
else:
	print(max_s)


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
maxans = float('-inf')
minans = 0
ans = True
pres = 0
for ai in a:
	pres += ai
	if pres < -w or pres > w:
		ans = False
		break
	if pres < 0:
		minans = max(minans, -pres)
	maxans = max(maxans, pres)
maxans = min(w - maxans, w)
print(max(0, maxans - minans + 1) if ans else 0)


(n, w) = list(map(int, input().split()))
a = list(map(int, input().split()))

def run():
	(max_lb, min_rb) = (0, w)
	(lb, rb) = (0, w)
	for x in a:
		if max_lb > min_rb:
			return 0
		lb += x
		rb += x
		max_lb = max(lb, max_lb)
		min_rb = min(rb, min_rb)
	if max_lb > min_rb:
		return 0
	return min_rb - max_lb + 1
x = run()
print(x)


(n, w) = map(int, input().split())
x = [int(w) for w in input().split()]
temp = 0
maxi = 0
mini = 0
for i in range(n):
	temp += x[i]
	maxi = max(maxi, temp)
	mini = min(mini, temp)
print(max(0, w - maxi + 1 + mini))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
from itertools import accumulate
b = list(accumulate(a))
(u, d) = (max(b), min(b))
if u - d > w:
	print(0)
	exit()
if u > w:
	print(0)
	exit()
ran = [max(0, -d), min(w, w - u)]
if ran[1] < ran[0]:
	print(0)
	exit()
print(ran[1] - ran[0] + 1)


(n, w) = list(map(int, input().split()))
L = list(map(int, input().split()))
maxim = 0
minin = 0
summa = 0
for i in range(n):
	summa += L[i]
	if summa > maxim:
		maxim = summa
	if summa < minin:
		minin = summa
print(max(0, w - maxim + minin + 1))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
(m, x, c) = (0, 0, 0)
for i in l:
	c = c + i
	m = min(c, m)
	x = max(x, c)
print(max(0, k - x + m + 1))


(n, w) = list(map(int, input().split()))
aa = list(map(int, input().split()))
x = 0
minx = 0
maxx = 0
for i in aa:
	x += i
	minx = min(x, minx)
	maxx = max(x, maxx)
if minx < 0:
	(minx, maxx) = (0, maxx - minx)
if maxx > w:
	print(0)
else:
	print(w - maxx + 1)


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
from itertools import accumulate
b = list(accumulate(a))
(c1, c2) = (max(b), min(b))
if c1 < 0:
	c1 = abs(c2)
elif c2 < 0:
	(c1, c2) = (c1 - c2, 0)
if c1 > w:
	print(0)
else:
	print(w - c1 + 1)


(n, w) = map(int, input().split())
alist = list(map(int, input().split()))
prefixsum = [0, alist[0]]
for i in range(1, n):
	prefixsum.append(prefixsum[-1] + alist[i])
minn = min(prefixsum)
maxx = max(prefixsum)
if maxx > w or maxx - minn > w:
	print(0)
elif minn < 0:
	if abs(minn) > w:
		print(0)
	else:
		for i in range(n + 1):
			prefixsum[i] += abs(minn)
		maxx = max(prefixsum)
		print(w - maxx + 1)
else:
	maxx = max(prefixsum)
	print(w - maxx + 1)


(n, w) = map(int, input().split())
lst = list(map(int, input().split()))
pre = [e for e in lst]
(mmin, mmax) = (pre[0], pre[0])
for i in range(1, len(lst)):
	pre[i] += pre[i - 1]
	mmin = min(mmin, pre[i])
	mmax = max(mmax, pre[i])
ans = 0
mmax = max(0, mmax)
ans = w - mmax + 1
if mmin < 0:
	ans += mmin
print(ans if ans > 0 else 0)


def solve(capacity, sequence):
	diff = 0
	(lb, ub) = (float('inf'), -float('inf'))
	for record in sequence:
		diff += record
		ub = max(ub, diff)
		lb = min(lb, diff)
	return max(0, capacity - max(0, ub) + min(0, lb) + 1)

def main():
	(_, capacity) = [int(x) for x in input().strip().split()]
	sequence = [int(x) for x in input().strip().split()]
	result = solve(capacity, sequence)
	print(result)
main()


def getinput():
	return [int(x) for x in input().strip().split()]
(n, k) = getinput()
arr = getinput()
for i in range(1, n):
	arr[i] += arr[i - 1]
maxval = max(arr)
minval = min(arr)
l = min(0, minval)
l = abs(l)
r = min(k - maxval, k)
if l > r:
	print(0)
else:
	print(r - l + 1)


aa = input()
(n, w) = [int(s) for s in aa.split(' ')]
aa = input()
a = [int(s) for s in aa.split(' ')]
x1 = 0
x2 = 0
s = 0
for el in a:
	s = s + el
	x1 = min(x1, s)
	x2 = max(x2, s)
res = w - x2 + x1 + 1
if res < 0:
	res = 0
print(res)


import itertools
(n, w) = map(int, input().split())
A = list(map(int, input().split()))
csA = list(itertools.accumulate(A))
if max(csA) > w:
	print(0)
	exit()
low = -min(0, min(csA))
high = min(w, w - max(csA))
print(high - low + 1 if low <= high else 0)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
mi = 0
ma = 0
k = 0
for i in range(n):
	k += a[i]
	if k > ma:
		ma = k
	if k < mi:
		mi = k
if m - ma + mi + 1 < 0:
	print(0)
else:
	print(m - ma + mi + 1)


(n, w) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
now = 0
mx = 0
mn = 1000000000.0
for i in a:
	now += i
	mx = max(mx, now)
	mn = min(mn, now)
if mn < 0:
	w -= abs(mn)
print(max(0, w - mx + 1))


nums = input().split()
num_stops = int(nums[0])
cap = int(nums[1])
stops = [0] + [int(n) for n in input().split()]
for i in range(1, num_stops + 1):
	stops[i] += stops[i - 1]
dif = max(stops) - min(stops)
count = cap - dif + 1
if count < 1:
	print(0)
else:
	print(count)


(n, w) = map(int, input().split())
arr = list(map(int, input().split()))
r = [0]
for i in arr:
	r += [r[-1] + i]
if w - max(r) + 1 + min(r) < 0:
	print(0)
else:
	print(w - max(r) + 1 + min(r))


(n, w) = [int(x) for x in input().split()]
an = [int(x) for x in input().split()]
max1 = 0
min1 = 0
total = 0
for i in range(len(an)):
	total += an[i]
	if total > max1:
		max1 = total
	elif total < min1:
		min1 = total
if max1 > w:
	print(0)
	exit()
if min1 < -w:
	print(0)
	exit()
ii = w - max(max1, 0)
ii1 = abs(min(min1, 0))
count = ii - ii1
if count >= 0:
	print(count + 1)
else:
	print(0)


rd = lambda : map(int, input().split())
(n, w) = rd()
(s, m, M) = [0] * 3
for x in rd():
	s += x
	m = min(m, s)
	M = max(M, s)
print(max(w - M + m + 1, 0))


import sys
line = sys.stdin.readline().split()
(n, w) = (int(line[0]), int(line[1]))
line = sys.stdin.readline().split()
nums = list(map(int, line))
minx = w
maxx = 0
accd = 0
for i in range(n):
	accd += nums[i]
	if accd < minx:
		minx = accd
	if accd > maxx:
		maxx = accd
minx = min(minx, 0)
print(max(w - maxx + minx + 1, 0))


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
(n, w) = mints()
x = 0
m = 0
M = 0
for a in mints():
	x += a
	m = min(m, x)
	M = max(M, x)
if M - m > w:
	print(0)
else:
	print(w - M + m + 1)


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
ma = -100000000000.0
su = 0
mi = 100000000000.0
for i in a:
	su += i
	ma = max(su, ma)
	mi = min(su, mi)
print(max(0, min(w, w - ma) - max(0, -mi) + 1))


yoar = list(map(int, input().split()))
n = yoar[0]
w = yoar[1]
arr = list(map(int, input().split()))
sumar = []
sumar.append(arr[0])
for i in range(1, n):
	sumar.append(arr[i] + sumar[i - 1])
mini = min(sumar)
maxa = max(sumar)
lf = 0
rg = 0
if maxa > w:
	print(0)
else:
	if mini < 0:
		lf = -mini
	else:
		lf = 0
	if maxa <= 0:
		rg = w
	else:
		rg = w - maxa
	if lf > rg:
		print(0)
	else:
		print(rg - lf + 1)


import logging
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(ch)

def solve(n, w, a):
	r = 0
	msf = -float('inf')
	minsf = float('inf')
	for i in a:
		r += i
		if r > w:
			return 0
		msf = max(msf, r)
		minsf = min(minsf, r)
	if w + minsf < 0:
		return 0
	return max(0, w - max(0, msf) - max(0, -minsf) + 1)

def main():
	(n, w) = map(int, input().strip().split())
	a = [int(x) for x in input().strip().split()]
	result = solve(n, w, a)
	print(result)
main()


(n, w) = input().split()
(n, w) = (int(n), int(w))
a = [int(i) for i in input().split()]
mi = ma = 0
cur = 0
for i in a:
	cur = cur + i
	mi = min(mi, cur)
	ma = max(ma, cur)
mi = 0 - mi
ma = w - ma
print(max(0, ma - mi + 1))


R = lambda : map(int, input().split())

def f():
	(n, w) = R()
	a = 0
	b = w
	s = 0
	for t in R():
		s += t
		if s < 0:
			a = max(a, -s)
		else:
			b = min(b, w - s)
	return max(0, b - a + 1)
print(f())


(n, w) = map(int, input().split())
l = map(int, input().split())
(a, b) = (0, w)
s = 0
for x in l:
	s += x
	if -s > a:
		a = -s
	if w - s < b:
		b = w - s
print(max(0, b - a + 1))


[n, w] = list(map(int, input().split()))
arr = list(map(int, input().split()))
(lw_lim, up_lim) = (0, w)
for idx in range(n):
	lw_lim = max(0, lw_lim - arr[n - idx - 1])
	up_lim = min(w, up_lim - arr[n - idx - 1])
print(max(0, up_lim - lw_lim + 1))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
r = 0
s = 0
smax = a[0]
smin = a[0]
for i in a:
	s += i
	smin = min(s, smin)
	smax = max(s, smax)
r = w - max(0, smax) + min(0, smin) + 1
r = max(r, 0)
print(r)


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
l = 100000000.0
h = -100000000.0
s = 0
for i in a:
	s += i
	l = min(s, l)
	h = max(s, h)
x = min(w, w - h) - max(0, -1 * l) + 1
print(max(0, x))


(n, w) = map(int, input().split())
l = list(map(int, input().split()))
low = 0
high = w
ans = -1
while low <= high:
	mid = low + (high - low) // 2
	cur = mid
	flag = 0
	for x in l:
		cur = x + cur
		if cur < 0:
			flag = 1
			break
		if cur > w:
			flag = 2
			break
	if flag == 1:
		low = mid + 1
		continue
	if flag == 2:
		high = mid - 1
		continue
	high = mid - 1
	ans = mid
low = 0
high = w
ans1 = -1
while low <= high:
	mid = low + (high - low) // 2
	cur = mid
	flag = 0
	for x in l:
		cur = x + cur
		if cur < 0:
			flag = 1
			break
		if cur > w:
			flag = 2
			break
	if flag == 1:
		low = mid + 1
		continue
	if flag == 2:
		high = mid - 1
		continue
	low = mid + 1
	ans1 = mid
if ans1 == ans and ans == -1:
	print(0)
	exit()
print(ans1 - ans + 1)


from sys import exit
(n, w) = map(int, input().split())
a = [int(x) for x in input().split()]
b = 0
minb = 0
maxb = 0
lf = 0
rg = w
for i in a:
	b += i
	minb = min(b, minb)
	maxb = max(b, maxb)
	if maxb > w:
		print(0)
		exit(0)
if minb < 0:
	lf = -minb
else:
	lf = 0
if maxb <= 0:
	rg = w
else:
	rg = w - maxb
print(0 if lf > rg else rg - lf + 1)


(n, w) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
for i in range(1, n):
	a[i] += a[i - 1]
num_max = max(a)
num_min = min(a)
ans_max = min(w - num_max, w)
ans_min = abs(min(0, num_min))
if 0 <= ans_min <= ans_max <= w:
	print(ans_max - ans_min + 1)
else:
	print(0)


import io
(nim, mike) = map(int, input().split())
listing = [int(x) for x in input().split()]
kite = [0]
for x in range(nim):
	kite.append(kite[x] + listing[x])
highest = max(kite)
lowest = min(kite)
if highest > mike or mike + lowest < 0:
	print(0)
else:
	print(max(mike - highest + lowest + 1, 0))


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(n, w) = iia()
arr = [0] + iia()
for i in range(1, n + 1):
	arr[i] += arr[i - 1]
(maxi, mini) = (max(arr), min(arr))
print(max(w + 1 - (maxi - mini), 0))


(n, w) = input().split()
d = [int(x) for x in input().split()]
n = int(n)
w = int(w)
c = 0
minm = 0
maxm = 0
l = 0
u = w
for x in d:
	c += x
	if c > maxm:
		maxm = c
		u = w - c
	if c < minm:
		minm = c
		l = -c
if l < 0 or l > w or u < 0 or (u > w) or (l > u):
	print(0)
else:
	print(u - l + 1)


(n, w) = list(map(int, input().split()))
arr = list(map(int, input().split()))
mx = 0
mn = 0
curr = 0
for i in arr:
	curr += i
	mx = max(curr, mx)
	mn = min(curr, mn)
ans = w + 1 - (mx - mn)
if ans < 0:
	print(0)
else:
	print(ans)


(n, w) = map(int, input().split())
spisok = list(map(int, input().split()))
max = 0
min = 0
summa = 0
for i in spisok:
	summa += i
	if summa > max:
		max = summa
	if summa < min:
		min = summa
p = w + min - max + 1
if p > w + 1 or p < 1 or max > w or (-min > w):
	print(0)
else:
	print(p)


(z, s, a, b) = (input, 0, 0, 0)
(n, m) = map(int, z().split())
for i in list(map(int, z().split())):
	s += i
	(a, b) = (min(a, s), max(b, s))
print(max(m - b + a + 1, 0))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
sol = 0
p = 0
b = []
i = 0
while i < n:
	sol = 0
	if a[i] >= 0:
		j = i
		while j < n and a[j] >= 0:
			sol += a[j]
			j += 1
		b.append(sol)
		i = j
	else:
		j = i
		while j < n and a[j] < 0:
			sol += a[j]
			j += 1
		b.append(sol)
		i = j
c = [0]
ans = 0
for i in range(len(b)):
	ans += b[i]
	c.append(ans)
ll = abs(max(c))
ll1 = abs(min(c))
print(max(0, w - ll1 - ll + 1))


(n, w) = map(int, input().split())
alist = list(map(int, input().split()))
k = 0
maxed = 0
mined = 0
for i in range(n):
	k += alist[i]
	maxed = max(k, maxed)
	mined = min(mined, k)
ans = w - (maxed + abs(mined)) + 1
print(max(ans, 0))


(n, w) = map(int, input().split())
l = list(map(int, input().split()))
ss = 0
cc = 0
if l[-1] < 0:
	c = w + l[-1]
c = sum(l)
for i in l:
	if i != -(w // n) or w % n != 0:
		cc = 1
		break
if l[-1] > 0:
	k = w
	kk = l[-1]
else:
	k = w + l[-1]
	kk = 0
for i in l[-1::-1]:
	if i < 0:
		if w - k < -i:
			k = w
		else:
			k = k - i
		if w - kk < -i:
			kk = w
		else:
			kk += -i
	else:
		if kk < i:
			kk = 0
		else:
			kk -= i
		k -= i
	if k < kk or k < 0 or kk > w:
		ss = 1
		break
	if k == w and kk == w:
		if cc == 1:
			ss = 1
			break
if ss == 0:
	print(k - kk + 1)
else:
	print(0)


import math
(n, w) = map(int, input().split())
a = list(map(int, input().split()))
maxx = -w
minn = w
sum = 0
for i in range(n):
	sum += a[i]
	if a[i] > 0:
		maxx = max(sum, maxx)
	elif a[i] < 0:
		minn = min(sum, minn)
maxx = w - maxx
maxx = min(w, maxx)
if minn == w:
	if maxx + 1 < 0:
		print(0)
	else:
		print(maxx + 1)
elif maxx - abs(minn) + 1 < 0:
	print(0)
else:
	print(maxx - abs(minn) + 1)


(n, w) = map(int, input().split())
arr = list(map(int, input().split()))
minn = 10 ** 100
maxx = -10 ** 100
summ = 0
for i in range(n):
	summ += arr[i]
	if summ < minn:
		minn = summ
	if summ > maxx:
		maxx = summ
flag = 0
if w + minn < 0:
	flag = 1
elif minn >= 0:
	start = 0
else:
	start = -minn
if maxx > w:
	flag = 1
elif maxx <= 0:
	end = w
else:
	end = w - maxx
if flag != 1 and start > end:
	flag = 1
if flag == 1:
	print(0)
else:
	print(end - start + 1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def pos(A, m):
	B = [m + i for i in pref]
	if max(B) > w:
		return False
	return True
(n, w) = l()
A = l()
pref = [A[0]]
for i in range(1, len(A)):
	pref.append(pref[-1] + A[i])
high = max(pref)
low = min(pref)
low = min(low, 0)
high = max(high, 0)
print(max(w - high + low + 1, 0))


(n, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
s = 0
b = [0]
for i in range(n):
	s = s + a[i]
	b.append(s)
c = min(b)
d = max(b)
if d - c > w:
	print(0)
else:
	print(w - (d - c) + 1)


(n, w) = input().split(' ')
n = int(n)
w = int(w)
a = list(input().split(' '))
fu = 0
ans = 0
ans2 = 0
for i in range(len(a)):
	a[i] = int(a[i])
	fu += a[i]
	ans = min(ans, fu)
	ans2 = max(ans2, fu)
if w + ans - ans2 + 1 < 0:
	print(0)
else:
	print(w + ans - ans2 + 1)


(n, w) = map(int, input().split())
a = [int(s) for s in input().split()]
(mi, ma, s) = (0, 0, 0)
for i in a:
	s += i
	if s < mi:
		mi = s
	elif s > ma:
		ma = s
if -mi <= w - ma:
	print(w - ma + mi + 1)
else:
	print(0)


(stops, m) = list(map(int, input().split()))
people = [int(i) for i in input().split()]
cM = 0
cm = 0
c = 0
for i in range(stops):
	c += people[i]
	if c > cM:
		cM = c
	if c < cm:
		cm = c
print(m - cM + cm + 1 if m - cM + cm + 1 >= 1 else 0)


import sys
ip = lambda : sys.stdin.readline().rstrip()
ip1 = lambda : map(int, ip().split())
arr = lambda : list(ip1())
inf = float('inf')
(n, k) = ip1()
a = arr()
(mn, mx) = (0, 0)
x = 0
for i in a:
	x += i
	mn = min(mn, x)
	mx = max(mx, x)
if abs(mn) > k or mx > k:
	ans = 0
else:
	mx = max(k - mx, 0)
	mn = abs(mn)
	if mn > mx:
		ans = 0
	else:
		ans = mx - mn + 1
print(ans)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	(n, w) = map(int, input().split())
	a = list(map(int, input().split()))
	(s, t) = (0, w)
	f = True
	cnt = 0
	for x in a:
		cnt += x
		if abs(cnt) > w or t < s:
			f = False
			break
		if cnt <= 0:
			s = max(abs(cnt), s)
		else:
			t = min(w - cnt, t)
	if not f:
		print(0)
	else:
		print(t - s + 1)
main()


R = lambda : map(int, input().split())
(n, m) = R()
s = 0
B = []
A = list(R())
for i in A:
	s += i
	B.append(s)
print(max(0, min(m, m - max(B)) - max(0, -min(B)) + 1))


a = input().split(' ')
a = [int(e) for e in a]
capacity = a[1]
l = input().split(' ')
l = [int(e) for e in l]
assert a[0] == len(l)
min_num = 0
max_num = 0
num = 0
for change in l:
	num += change
	if min_num == None or num < min_num:
		min_num = num
	if max_num == None or num > max_num:
		max_num = num
print(max(capacity - max_num + min_num + 1, 0))


l = input().split()
n = int(l[0])
w = int(l[1])
l = input().split()
li = [int(i) for i in l]
left = 0
right = w
sumi = 0
for i in range(n):
	sumi += li[i]
	left = max(left, -1 * sumi)
	right = min(right, w - sumi)
print(max(right - left + 1, 0))


data1 = list(map(int, input().split()))
data2 = list(map(int, input().split()))
k = 0
o = 0
h = 0
for i in range(data1[0]):
	k += data2[i]
	if k >= o:
		o = k
	if k < h:
		h = k
ans = data1[1] - (o + abs(h)) + 1
if ans > 0:
	print(ans)
else:
	print(0)


(n, w) = map(int, input().split())
line = list(map(int, input().split()))
summ = list(line)
for i in range(1, len(line)):
	summ[i] += summ[i - 1]
M = max(summ) if max(summ) > 0 else 0
m = min(summ) if min(summ) < 0 else 0
if w - M + m + 1 >= 0:
	print(w - M + m + 1)
else:
	print(0)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
top = 0
bot = 0
cur = 0
for i in a:
	cur += i
	top = max(top, cur)
	bot = min(bot, cur)
if top - bot > m:
	print(0)
else:
	print(m + 1 - top + bot)


(n, w) = map(int, input().split())
cs = [int(i) for i in input().split()]
ccs = [0]
for i in range(n):
	ccs.append(ccs[-1] + cs[i])
m = -min(ccs)
M = w - max(ccs)
print(max([0, M - m + 1]))


import sys
from itertools import *
read = lambda : map(int, sys.stdin.buffer.readline().split())
(n, w) = read()
a = [0] + list(accumulate(read()))
(b, c) = (min(a), max(a))
print(max(0, w - c - -b + 1))


def solution(n, w, bs):
	current = min_ = max_ = bs[0]
	min_pass = max_pass = 0
	for item in bs[1:]:
		current += item
		min_ = min(current, min_)
		max_ = max(current, max_)
	if max_ > w:
		return 0
	elif max_ <= 0:
		max_pass = w
	else:
		max_pass = w - max_
	if min_ < 0:
		min_pass = min_
	return 0 if -min_pass > max_pass else max_pass + min_pass + 1
import sys
(n, w) = sys.stdin.readline().split()
a = [int(i) for i in sys.stdin.readline().split()]
sys.stdout.write(str(solution(int(n), int(w), a)) + '\n')


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
(minw, maxw) = (0, w)
k = 0
for e in a:
	w -= e
	k -= e
	maxw = min(w, maxw)
	minw = max(minw, k)
if minw > maxw:
	print(0)
else:
	print(maxw - minw + 1)


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
l = 0
s = 0
k = 0
for i in range(n):
	k += a[i]
	if k > l:
		l = k
	if k < s:
		s = k
print(max(w - l + s + 1, 0))


from sys import maxsize
mini = maxsize
maxi = -maxsize
s = 0
(n, k) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
for i in arr:
	s += i
	maxi = max(s, maxi)
	mini = min(mini, s)
if maxi < 0:
	ans = k + 1
else:
	ans = k - maxi + 1
if mini < 0:
	ans += mini
if ans <= 0:
	print('0')
else:
	print(ans)


numList = [int(x) for x in input().split(' ')]
n = numList[0]
w = numList[1]
numList = [int(x) for x in input().split(' ')]
minNumber = 99999999
maxNumber = 0
for i in range(len(numList)):
	if i > 0:
		numList[i] += numList[i - 1]
	if minNumber > numList[i]:
		minNumber = numList[i]
	if maxNumber < numList[i]:
		maxNumber = numList[i]
if len(numList) == 1:
	ans = w - abs(numList[0]) + 1
else:
	lowerLimit = 0 if minNumber >= 0 else -minNumber
	maxNumber += lowerLimit
	ans = w - maxNumber + 1
if ans > 0:
	print(ans)
else:
	print(0)


(n, w) = map(int, input().split())
A = list(map(int, input().split()))
x = 0
p = 10 ** 10
q = 0
for i in A:
	x += i
	p = min(p, x)
	q = max(q, x)
print(max(0, w - q + min(0, p) + 1))


ans_ = []

def read():
	return list(map(int, input().strip().split(' ')))
(n, w) = read()
arr = read()
(lo, up) = (0, w)
tem = 0
ans = 0
fl = 1
for i in arr:
	tem += i
	if tem > 0:
		up = min(up, w - tem)
	else:
		lo = max(lo, abs(tem))
ans = max(0, up - lo + 1)
ans_.append(ans)
for i in ans_:
	print(i)


def check1(x, arr, n, w):
	for i in range(n):
		x += arr[i]
		if x > w:
			return False
	return True

def check2(x, arr, n, w):
	for i in range(n):
		x += arr[i]
		if x < 0:
			return False
	return True
(n, w) = map(int, input().strip().split(' '))
arr = list(map(int, input().strip().split(' ')))
low = 0
high = w
ans = -1
ans1 = -1
while low <= high:
	mid = (low + high) // 2
	if check1(mid, arr, n, w):
		ans = mid
		low = mid + 1
	else:
		high = mid - 1
low = w
high = 0
while high <= low:
	mid = (low + high) // 2
	if check2(mid, arr, n, w):
		low = mid - 1
		ans1 = mid
	else:
		high = mid + 1
if ans == -1 or ans1 == -1 or ans < ans1:
	print(0)
else:
	print(ans - ans1 + 1)


(n, w) = map(int, input().split())
A = list(map(int, input().split()))
from itertools import accumulate
C = [0] + A
C = list(accumulate(C))
M = max(C)
m = min(C)
l = max(0, -m)
r = min(w - M, w)
if l > r:
	print(0)
else:
	print(r - l + 1)


(n, w) = map(int, input().split())
v = list(map(int, input().split()))
(mini, maxi) = (0, 0)
s = 0
for i in range(n):
	s += v[i]
	mini = min(mini, s)
	maxi = max(maxi, s)
res = max(0, w - (maxi - mini) + 1)
print(res)


import sys

def solve(io):
	N = io.readInt()
	W = io.readInt()
	A = io.readIntArray(N)
	lo = 0
	hi = 0
	curr = 0
	for v in A:
		curr += v
		lo = min(lo, curr)
		hi = max(hi, curr)
	io.println(max(0, W + 1 - (hi - lo)))

class IO:
	input = None
	output = None
	raw = ''
	buf = []
	pos = 0

	def __init__(self, inputStream, outputStream):
		self.input = inputStream
		self.output = outputStream

	def readToBuffer(self):
		self.raw = self.input.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def readString(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def readInt(self):
		return int(self.readString())

	def readFloat(self):
		return float(self.readString())

	def readStringArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readString())
		return arr

	def readIntArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readInt())
		return arr

	def readFloatArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readFloat())
		return arr

	def readLine(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		if self.pos > 0:
			raise ValueError('Cannot call readline in the middle of a line.')
		return self.raw

	def print(self, s):
		self.output.write(str(s))

	def println(self, s):
		self.print(s)
		self.print('\n')

	def printlnArray(self, arr, sep=' '):
		self.println(sep.join((str(x) for x in arr)))

	def flushOutput(self):
		self.output.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flushOutput()


(n, w) = map(int, input().split())
l = list(map(int, input().split()))
sm = 0
mn = 0
mx = 0
for i in l:
	sm += i
	mn = min(mn, sm)
	mx = max(mx, sm)
print(max(w + mn - mx + 1, 0))


(n, w) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
mx = 0
mn = 0
cur = 0
for aa in a:
	cur += aa
	mx = max(cur, mx)
	mn = min(cur, mn)
up = w - mx + 1
down = abs(mn)
if down > up:
	print(0)
else:
	print(up - down)


(n, w) = map(int, input().split())
L = list(map(int, input().split()))
res = 0
a = [i for i in L]
for i in range(1, n):
	a[i] = a[i] + a[i - 1]
(ma, mi) = (max(a), min(a))
ma = max(ma, 0)
mi = min(mi, 0)
p = w - ma + mi + 1
if p > 0:
	print(p)
else:
	print(0)


I = lambda : list(map(int, input().split()))
(n, w) = I()
a = I()
(mn, mx) = (0, w)
s = 0
for i in range(n):
	s += a[i]
	if s < 0:
		mn = max(mn, -s)
	else:
		mx = min(mx, w - s)
print(max(mx + 1 - mn, 0))


(n, w) = list(map(int, input().split()))
cur_delta = max_delta = min_delta = 0
for ai in map(int, input().split()):
	cur_delta += ai
	max_delta = max(max_delta, cur_delta)
	min_delta = min(min_delta, cur_delta)
min_res = 0 - min_delta
max_res = w - max_delta
if max_res < min_res:
	print('0')
else:
	print(max_res + 1 - min_res)


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
L = 0
R = w
c = [0] * (n + 1)
for i in range(1, n + 1):
	c[i] = c[i - 1] + a[i - 1]
L = -min(c)
R = w - max(c)
if R - L + 1 < 0:
	print(0)
else:
	print(R - L + 1)


(n, w) = map(int, input().split())
a = [int(x) for x in input().split()]
(l, r) = (0, w)
cur = 0
for x in a:
	cur += x
	if cur < 0:
		l = max(l, abs(cur))
	elif cur > 0:
		r = min(r, w - cur)
print(max(0, r - l + 1))


(N, W) = (int(i) for i in input().split())
L = [int(i) for i in input().split()]
n = 0
left = 0
right = W
for i in L:
	n += i
	if n + right > W:
		right -= n + right - W
	if n + left < 0:
		left += -(n + left)
print(max(right - left + 1, 0))


import sys
input = sys.stdin.readline

def solve(n, w, a):
	(cum, mx, mn) = (0, 0, 0)
	(cap_mx, cap_mn) = (w, w)
	for ai in a:
		cum += ai
		if cum < mn:
			mn = cum
		if cum > mx:
			mx = cum
	if w + 1 - -mn - mx <= 0:
		return 0
	return w + 1 - -mn - mx
(n, w) = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, w, a))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
max_p = 0
min_p = 0
s = 0
for step in a:
	s += step
	if s > max_p:
		max_p = s
	if s < min_p:
		min_p = s
d = max_p - min_p
if w - d + 1 > 0:
	print(w - d + 1)
else:
	print(0)


(n, w) = map(int, input().split())
ar = list(map(int, input().split()))
difs = []
s = 0
for x in range(n):
	s += ar[x]
	difs.append(s)
(minn, maxx) = (min(difs), max(difs))
(maxres, minres) = (w, 0)
if maxx > 0:
	maxres -= maxx
if minn < 0:
	minres -= minn
if maxres < 0 or minres > w or minres > maxres:
	print(0)
else:
	print(maxres - minres + 1)


params = [int(s) for s in input().split(' ')]
n = params[0]
w = params[1]
deltas = [int(s) for s in input().split(' ')]
cur = 0
min_ = 0
for delta in deltas:
	cur += delta
	if cur < 0:
		min_ += abs(cur)
		cur = 0
	if cur > w:
		print(0)
		exit()
cur = w
max_ = w
for delta in deltas:
	cur += delta
	if cur > w:
		max_ -= cur - w
		cur = w
	if cur < 0:
		print(0)
		exit()
if max_ < min_:
	print(0)
else:
	print(max_ - min_ + 1)


(n, w) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0 for i in range(n + 1)]
b[0] = 0
for i in range(n):
	b[i + 1] = b[i] + a[i]
k = min(b)
if k < 0:
	for i in range(n + 1):
		b[i] -= k
if max(b) > w:
	print(0)
else:
	print(w - max(b) + 1)


(n, w) = [int(x) for x in input().rstrip().split()]
min_val = 10000000000
max_val = 0
cur_val = 0
for x in input().rstrip().split():
	cur_val += int(x)
	if cur_val < min_val:
		min_val = cur_val
	if cur_val > max_val:
		max_val = cur_val
min_pass = 0
if min_val < 0:
	min_pass = -min_val
result = w - max_val - min_pass + 1
if result < 0:
	print(0)
else:
	print(result)


from itertools import accumulate
(n, w) = map(int, input().split())
arr = list(accumulate(list(map(int, input().split()))))
upper = abs(max(0, max(arr)))
lower = abs(min(0, min(arr)))
print(max(0, w - upper - lower + 1))


(n, w) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
a = 0
b = 0
s = 0
for x in arr:
	s += x
	a = max(a, s)
	b = min(s, b)
print(max(0, w - a + b + 1))


from sys import stdin, stdout
input = stdin.readline
t = 1
for _ in range(t):
	(n, w) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = []
	s = 0
	for i in a:
		s += i
		b.append(s)
	x = max(b)
	if x > w:
		print(0)
		continue
	if x < 0:
		y = min(b)
		val = abs(y)
		if val > w:
			print(0)
			continue
		else:
			print(w - val + 1)
			continue
	x = w - x
	y = min(b)
	if y >= 0:
		print(x + 1)
		continue
	y = abs(y)
	ans = x - y + 1
	if ans < 0:
		ans = 0
	print(ans)


(n, w) = map(int, input().split(' '))
numbers = list(map(int, input().split(' ')))
sums = [numbers[0]]
for i in numbers:
	sums.append(sums[-1] + i)
mi = min(sums)
ma = max(sums)
if w - (ma - mi) + 1 > 0:
	print(w - (ma - mi) + 1)
else:
	print(0)


(stops, cap) = map(int, input().split())
stop = [int(ai) for ai in input().split(' ')]
sums = 0
mins = 0
maks = 0
cap += 1
try:
	for s in stop:
		sums += s
		if abs(sums) > cap:
			raise Exception()
		if maks < sums:
			maks = sums
		if mins > sums:
			mins = sums
	if cap - maks + mins < 0:
		print(0)
	else:
		print(cap - (maks - mins))
except:
	print(0)


(n, m) = map(int, input().split())
ans = tmp = 0
mi = mx = 0
lis = list(map(int, input().split()))
for i in range(n):
	tmp += lis[i]
	if tmp >= 0:
		mx = max(mx, tmp)
	else:
		mi = min(mi, tmp)
ini = m - mx
if abs(mi) > ini:
	print(0)
else:
	print(ini - abs(mi) + 1)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr2 = []
arr2.append(arr[0])
for i in range(1, n):
	arr2.append(arr2[-1] + arr[i])
x = 0 - min(arr2)
if x <= 0:
	x = 0
y = m - max(arr2)
if y > m:
	y = m
if y < 0 or x > m or x > y:
	print(0)
else:
	print(y - x + 1)


T = input().split(' ')
n = int(T[0])
w = int(T[1])
S = input().split(' ')
for i in range(len(S)):
	S[i] = int(S[i])
m = 0
M = 0
t = 0
for i in range(len(S)):
	t += S[i]
	M = max(M, t)
	m = min(m, t)
if -m <= w - M:
	print(w - M + m + 1)
else:
	print(0)


(n, w) = map(int, input().split())
o = list(map(int, input().split()))
mn = 10 ** 9 + 1
mx = -mn
s = 0
for e in o:
	s += e
	mx = max(mx, s)
	mn = min(mn, s)
a = range(-mn if mn < 0 else 0, w - mx + 1 if mx > 0 else w + 1)
print(len(a))


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
prefix = [0]
(neg, pos) = ([], [])
for i in range(0, len(arr)):
	prefix.append(arr[i] + prefix[-1])
	if prefix[-1] < 0:
		neg.append(abs(prefix[-1]))
	else:
		pos.append(prefix[-1])
negg = max(neg) if len(neg) > 0 else 0
poss = max(pos) if len(pos) > 0 else 0
if poss > k:
	print(0)
else:
	lower = negg
	upper = k - poss
	if lower > upper:
		print(0)
	else:
		print(upper - lower + 1)


(n, a) = map(int, input().split())
(b, lo, hi) = (0, 0, 0)
for i in input().split():
	b += int(i)
	lo = min(lo, b)
	hi = max(hi, b)
print(max(a - hi + lo + 1, 0))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
now = 0
(M, m) = (0, 0)
for ai in a:
	now += ai
	M = max(M, now)
	m = min(m, now)
print(max(0, w - M + m + 1))


(n, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
maxi = 0
mini = 0
net = 0
for i in range(n):
	net += a[i]
	if maxi < net:
		maxi = net
	if mini > net:
		mini = net
if maxi - mini > w:
	print('0')
	exit()
print('%d' % (w + 1 - (maxi - mini)))
exit()


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
b = []
b.append(a[0])
for i in range(1, n):
	b.append(b[-1] + a[i])
l = min(b)
r = max(b)
left = 0
right = w
if l < 0:
	left -= l
if r > 0:
	right -= r
print(max(0, right - left + 1))


GI = lambda : int(input())
GIS = lambda : map(int, input().split())
LGIS = lambda : list(GIS())

def main():
	(_, cap) = GIS()
	mnbal = mxbal = balance = 0
	for d in GIS():
		balance += d
		mnbal = min(mnbal, balance)
		mxbal = max(mxbal, balance)
	range_top = cap - mxbal
	range_bottom = -1 * mnbal
	range_width = range_top - range_bottom + 1
	print(max(range_width, 0))
main()


(n, w) = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
summ = 0
mmax = w
mmin = 0
for i in range(n):
	cur = a[i]
	if cur >= 0:
		summ += cur
		mmax = min(mmax, w - summ)
	else:
		cmp = 0
		if summ + cur < 0:
			cmp = abs(summ + cur)
		mmin = max(mmin, cmp)
		summ += cur
if mmax < mmin:
	print(0)
else:
	print(mmax - mmin + 1)


from itertools import accumulate
(n, w) = map(int, input().split())
a = list(map(int, input().split()))
a_sum = list(accumulate(a))
min_a = min(a_sum)
max_a = max(max(a_sum), 0)
if min_a < 0:
	max_a -= min_a
print(max(w - max_a + 1, 0))


(n, w) = map(int, input().split())
lst = [int(x) for x in input().split()]
a = [0]
for x in range(n):
	a.append(a[x] + lst[x])
maxi = max(a)
mini = min(a)
if maxi > w or w + mini < 0:
	print(0)
else:
	print(max(w - maxi + mini + 1, 0))


(n, cap) = map(int, input().split())
a = list(map(int, input().split()))
mn = float('inf')
mx = -float('inf')
cur = 0
for val in a:
	cur += val
	if cur > cap:
		print(0)
		exit()
	mn = min(mn, cur)
	mx = max(mx, cur)
mn = -mn if mn < 0 else 0
mx = cap if mx <= 0 else cap - mx
print(max(0, mx - mn + 1))


(n, w) = map(int, input().split())
a = map(int, input().split())
lower = higher = current = 0
for a_i in a:
	current += a_i
	if current < lower:
		lower = current
	if current > higher:
		higher = current
lower = abs(lower)
higher = w - higher
if higher - lower + 1 < 0:
	print(0)
else:
	print(higher - lower + 1)


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
min_a = 0
max_a = w
s = 0
f = 1
for i in range(n):
	s += a[i]
	if s > 0:
		max_a = min(max_a, w - s)
		if max_a > w or max_a < 0:
			f = 0
			break
	else:
		min_a = max(min_a, abs(s))
		if min_a < 0 or min_a > w:
			f = 0
			break
	if max_a < min_a:
		f = 0
		break
if f:
	print(max_a - min_a + 1)
else:
	print(0)


(n, w) = map(int, input().split())
m = list(map(int, input().split()))
t = 0
mi = 100000000000.0
ma = -100000000000.0
for elem in m:
	t += elem
	ma = max(ma, t)
	mi = min(mi, t)
if ma <= 0:
	print(max(w - abs(mi) + 1, 0))
elif mi <= 0:
	print(max(w - ma + 1 - abs(mi), 0))
else:
	print(max(w - ma + 1, 0))


(n, c) = [int(i) for i in input().strip().split()]
stops = [int(i) for i in input().strip().split()]
lps = 0
lns = 0
s = 0
flag = False
for i in stops:
	s += i
	if s + c < 0:
		flag = True
		break
	lps = max(s, lps)
	lns = min(s, lns)
if flag:
	print(0)
else:
	print(c - lps + lns + 1) if c - lps + lns + 1 > 0 else print(0)


from sys import stdin

def main():
	(n, w) = map(int, stdin.readline().split())
	b = [0]
	ar = list(map(int, stdin.readline().split()))
	for elm in ar:
		b.append(b[-1] + elm)
	high = w - max(b)
	low = -min(b)
	if high >= low:
		print(high - low + 1)
	else:
		print(0)
main()


(n, w) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
x = 0
le = []
ge = []
for i in range(n):
	x += a[i]
	if w - x < 0:
		print(0)
		exit()
	elif w - x <= w:
		le.append(w - x)
	if -x > w:
		print(0)
		exit()
	elif -x >= 0:
		ge.append(-x)
le.sort()
ge.sort(reverse=True)
if len(le) == 0 and len(ge) == 0:
	print(w + 1)
elif len(le) == 0:
	print(w - ge[0] + 1)
elif len(ge) == 0:
	print(le[0] + 1)
elif ge[0] > le[0]:
	print(0)
else:
	print(le[0] - ge[0] + 1)


(n, w) = list(map(int, input().split()))
aa = list(map(int, input().split()))
mx = 0
mn = 0
sum = 0
for a in aa:
	sum += a
	if sum > mx:
		mx = sum
	if sum < mn:
		mn = sum
print(max(w - mx + mn + 1, 0))


from sys import stdin, stdout
import math
(N, W) = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]
mini = 999999999999
maxi = -1
s = 0
for i in range(N):
	s += arr[i]
	mini = min(mini, s)
	maxi = max(maxi, s)
r = [0, W]
if arr[0] < 0:
	r = [abs(arr[0]), W]
elif arr[0] > 0:
	r = [0, W - arr[0]]
L = -mini
R = W - maxi
r[0] = max(L, r[0])
r[1] = min(R, r[1])
if r[1] >= r[0]:
	print(r[1] - r[0] + 1)
else:
	print(0)


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
u = 0
l = 0
c = 0
for el in a:
	c += el
	if c > u:
		u = c
	elif c < l:
		l = c
if u - l > w:
	print(0)
else:
	print(w - (u - l) + 1)


(n, w) = map(int, input().split())
b = []
a = list(map(int, input().split()))
b.append(0)
for i in range(n):
	b.append(b[-1] + a[i])
m = min(b)
if m < 0:
	m *= -1
	for i in range(n + 1):
		b[i] = b[i] + m
m = max(b)
if m > w:
	print(0)
else:
	print(w - m + 1)


def fun(n, w, a):
	(l, h) = (0, w)
	for change in a[::-1]:
		l -= change
		h -= change
		if l < 0:
			l = 0
		if h > w:
			h = w
	if l > h:
		return 0
	return h - l + 1
(n, w) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
print(fun(n, w, a))


(n, m) = map(int, input().split())
(f, s) = (0, 0)
p = 0
for i in list(map(int, input().split())):
	p += i
	if p < 0:
		f = min(f, p)
	if p > 0:
		s = max(s, p)
print(0 if s > m or -f > m or m - s < -f else m - s + f + 1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
high = 0
low = 0
curr = 0
for x in l:
	curr += x
	high = max(curr, high)
	low = min(curr, low)
if k + low < 0:
	print(0)
	exit()
print(max(k - (high - low) + 1, 0))


line = [int(x) for x in input().split()]
n = line[0]
w = line[1]
arr = [int(x) for x in input().split()]
(_min, _max) = (0, 0)
_sum = 0
for x in arr:
	_sum += x
	if _max < _sum:
		_max = _sum
	if _min > _sum:
		_min = _sum
if w - _max + _min + 1 > -1:
	print(w - _max + _min + 1)
else:
	print(0)


from itertools import *
(n, w) = map(int, input().split())
s = list(map(int, input().split()))
s = list(accumulate(s))
s.append(0)
mini = min(s)
maxi = max(s)
print(max(0, w - maxi + mini + 1))


(a, t) = list(map(int, input().split()))
s = list(map(int, input().split()))
w = [s[0]]
for i in s[1:]:
	w.append(w[-1] + i)
r = max(w)
o = min(w)
if r - o > t or abs(o) > t or r > t:
	print(0)
else:
	if o > 0:
		o = 0
	elif r < 0:
		r = 0
	print(t - (r - o) + 1)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(n, w) = sep()
	a = lis()
	upper = [w] * (n + 1)
	lower = [0] * (n + 1)
	for i in range(0, n):
		lower[i + 1] = lower[i] + a[i]
	for i in range(0, n):
		upper[i + 1] = upper[i] + a[i]
	chota = min(lower)
	for i in range(0, n + 1):
		lower[i] += -chota
	for i in range(0, n + 1):
		if lower[i] > w:
			print(0)
			return
	bada = max(upper) - w
	for i in range(0, n + 1):
		upper[i] -= bada
	for i in range(0, n + 1):
		if upper[i] < 0:
			print(0)
			return
	ans = upper[0] - lower[0] + 1
	if ans >= 0:
		print(ans)
	else:
		print(0)
testcase(1)


(n, w) = map(int, input().split())
(maxp, minp) = (0, 0)
a = list(map(int, input().split()))
now = 0
for i in range(n):
	now += a[i]
	maxp = max(maxp, now)
	minp = min(minp, now)
print(max(0, w - maxp + minp + 1))


(n, w) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
l = [0]
(mn, mx) = (0, 0)
for i in range(n):
	l.append(l[i] + a[i])
	if l[-1] < mn:
		mn = l[-1]
	elif l[-1] > mx:
		mx = l[-1]
diff = mx - mn
if diff <= w:
	print(w - diff + 1)
else:
	print(0)


(n, w) = map(int, input().split())
l = list(map(int, input().split()))
flag = 0
ans = 0
cur = 0
for x in l:
	e = x + cur
	if e > w:
		flag = 1
		break
	if e < 0:
		ans += abs(e)
		e = 0
		cur = 0
		continue
	cur = e
if flag:
	print(0)
	exit()
ans1 = w
cur = w
for x in l:
	e = cur + x
	if e < 0:
		flag = 1
		break
	if e > w:
		ans1 -= e - w
		cur = w
		continue
	cur = e
if flag:
	print(0)
	exit()
print(ans1 - ans + 1)


(n, w) = list(map(int, input().split(' ')))
stops = list(map(int, input().split(' ')))
(mini, maxi, curr) = (0, 0, 0)
for stop in stops:
	curr += stop
	if curr < mini:
		mini = curr
	if curr > maxi:
		maxi = curr
theminimum = abs(min(0, mini))
themaximum = w - maxi
print(max(themaximum - theminimum, -1) + 1)


(z, zz, dgraphs) = (input, lambda : list(map(int, z().split())), {})
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, w) = zz()
l = zz()
(mi, mx) = (0, 0)
t = 0
for i in l:
	t += i
	mx = max(t, mx)
	mi = min(mi, t)
print(max(0, w - mx + 1 + mi))


(n, k) = map(int, input().split())
lis = [*map(int, input().split())]
m = c = 0
ans1 = ans2 = 0
for i in lis:
	m += i
	ans1 = max(ans1, m)
	ans2 = min(ans2, m)
print(max(0, k + 1 - ans1 + ans2))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
(mx, mn, bal) = (0, 0, 0)
for aa in a:
	bal += aa
	(mx, mn) = (max(mx, bal), min(mn, bal))
(left, right) = (-mn, w - mx)
if right < 0 or left > right:
	print(0)
else:
	print(right - left + 1)


(n, w) = map(int, input().split())
Amin = 0
Amax = 0
s = 0
for i in list(map(int, input().split())):
	s += i
	if s > Amax:
		Amax = s
	if s < Amin:
		Amin = s
ans = w - Amax + Amin + 1
if ans < 0:
	print(0)
else:
	print(ans)


(n, w) = list(map(int, input().strip().split(' ')))
arr = list(map(int, input().strip().split(' ')))
l = 0
m = 0
n = 0
for i in arr:
	l += i
	m = max(l, m)
	n = min(l, n)
print(max(0, w - m + n + 1))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
(ma, mi) = (0, 0)
for i in a:
	s += i
	ma = max(ma, s)
	mi = min(mi, s)
x = w - ma
y = -mi
ans = max(x - y + 1, 0)
print(ans)


(n, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
prefix = [0]
summ = 0
for i in range(n):
	summ += a[i]
	prefix.append(summ)
r = max(prefix)
t = min(prefix)
cnt1 = 0
if t < 0:
	cnt1 += abs(t)
cnt2 = w - r
if cnt2 - cnt1 + 1 <= 0:
	print(0)
else:
	print(cnt2 - cnt1 + 1)


(n, w) = map(int, input().split())
arr = list(map(int, input().split()))
pref = [0] * n
pref[0] = arr[0]
for i in range(1, n):
	pref[i] = arr[i] + pref[i - 1]
maxx = max(max(pref), 0)
minn = min(min(pref), 0)
if w - maxx + 1 + minn < 0:
	print(0)
else:
	print(w - maxx + 1 + minn)


import itertools
(n, w) = map(int, input().split())
A = list(map(int, input().split()))
if min(A) >= 0:
	print(max(w - sum(A) + 1, 0))
	exit()
if max(A) <= 0:
	print(max(w + sum(A) + 1, 0))
	exit()
csA = list(itertools.accumulate(A))
if max(csA) > w:
	print(0)
	exit()
if min(csA) < -w:
	print(0)
	exit()
low = abs(min(csA))
if max(csA) > 0:
	ans = w - max(csA) - low + 1
	print(max(ans, 0))
else:
	ans = w + min(csA) + 1
	print(max(ans, 0))


(n, w) = map(int, input().split())
min = 10 ** 9
max = -10 ** 9
arr = list(map(int, input().split()))
n = len(arr)
curr = 0
for i in range(n):
	curr += arr[i]
	if curr < min:
		min = curr
	if curr > max:
		max = curr
if min <= 0:
	min = -1 * min
else:
	min = 0
if max <= 0:
	max = w
else:
	max = w - max
if min < 0 or max > w or max < min:
	print(0)
else:
	print(max - min + 1)


from itertools import accumulate
(n, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
s_a = [0] + list(accumulate(a))
(mn, mx) = (min(s_a), max(s_a))
mn_ = max(0, -mn)
mx_ = w - mx
if mx_ < 0 or mx_ < mn_ or mn_ > w or (mx - mn > w) or (mx_ - mn_ > w) or (mn < -w) or (mx > w) or (min(a) < -w) or (max(a) > w):
	print(0)
	return
print(mx_ - mn_ + 1)


input1 = input().split()
w = int(input1[1])
input2 = input().split()
b = 0
bmin = 0
bmax = 0
for x in input2:
	b += int(x)
	if b > bmax:
		bmax = b
	if bmin > b:
		bmin = b
if bmax > w or abs(bmin) > w:
	print('0')
elif w - bmax + bmin + 1 < 0:
	print('0')
else:
	print(w - bmax + bmin + 1)


(n, w) = map(int, input().split())
x = [int(w) for w in input().split()]
mini = x[0]
maxi = x[0]
temp = x[0]
for i in range(1, n):
	temp += x[i]
	maxi = max(temp, maxi)
	mini = min(temp, mini)
if maxi > w:
	print(0)
else:
	if maxi <= 0:
		a = w
	else:
		a = w - maxi
	if mini < 0:
		b = -mini
	else:
		b = 0
	print(max(0, a - b + 1))


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
(N, W) = MAP()
A = LIST()
lo = 0
hi = W
for a in A[::-1]:
	lo = max(lo - a, 0)
	hi = min(hi - a, W)
ans = max(hi - lo + 1, 0)
print(ans)


(n, w) = map(int, input().split())
a = [int(i) for i in input().split()]
x1 = 0
k = 0
x2 = w
for i in a:
	if abs(i) > w:
		k += 1
	x1 = x1 + i
	x2 = x2 + i
	if x2 > w and x1 < 0:
		k += 1
	x1 = max(x1, 0)
	x2 = min(x2, w)
x = max(0, x2 - x1 + 1)
print(x if k == 0 else 0)


(n, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
cur = 0
(mn, mx) = (0, w)
for el in a:
	cur += el
	if cur < 0:
		mn = max(mn, abs(cur))
	else:
		mx = min(mx, w - cur)
if mn > mx:
	print(0)
else:
	print(mx - mn + 1)


(n, w) = map(int, input().split())
A = tuple(map(int, input().split()))
S = [A[0]]
for i in range(n - 1):
	S.append(A[i + 1] + S[-1])
(m, M) = (int(10000000.0), 0)
for i in S:
	M = max(i, M)
	m = min(i, m)
if -m > w or M > w or M - m > w:
	print(0)
	exit(0)
if m >= 0:
	print(w - M + 1)
else:
	print(w + m + 1 - M)


(n, w) = map(int, input().split())
a = [int(x) for x in input().split()]
mind = 0
maxd = 0
cur = 0
for x in a:
	cur += x
	mind = min(mind, cur)
	maxd = max(maxd, cur)
up_bound = w - maxd
low_bound = 0 - mind
if low_bound > up_bound:
	print(0)
else:
	print(up_bound - low_bound + 1)


(n, w) = map(int, input().split())
lst = [int(x) for x in input().split()]
a = 0
b = 0
x = 0
for m in lst:
	x += m
	if x > a:
		a = x
	if x < b:
		b = x
n = w - a + 1
if b < 0:
	n += b
if n >= 0:
	print(n)
else:
	print(0)


def sol():
	(n, w) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	m = 0
	now = 0
	nowHave = 0
	out = [0] * n
	for i in range(n):
		nowHave += arr[i]
		out[i] = nowHave
		now = max(now, now + arr[i])
		m = max(now, m)
	print(max(w - max(max(out), 0) - max(-1 * min(out), 0) + 1, 0))
sol()


(n, w) = input().split()
w = int(w)
a = input().split()
ans = True
pas = 0
lim_pas = w
for elem in a:
	if ans:
		pas = pas + int(elem)
		if pas > w:
			print(0)
			ans = False
			break
		elif pas < 0:
			lim_pas = lim_pas + pas
			pas = 0
			if lim_pas < 0:
				print(0)
				ans = False
				break
		lim_pas = min(lim_pas, w - pas)
if ans:
	print(lim_pas + 1)


(n, w) = map(int, input().split())
(s, l, h) = (0, 0, 0)
for a in input().split():
	s += int(a)
	l = min(l, s)
	h = max(h, s)
print(max(w - h + l + 1, 0))


import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
import itertools
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
(n, w) = inpl()
a = inpl()
aa = list(itertools.accumulate(a))
mx = max(aa)
mi = min(aa)
if max(a) > w or abs(min(a)) > w or mx > w or (abs(mi) > w):
	print(0)
	quit()
print(max(w - (max(0, mx) - min(0, mi)) + 1, 0))


(n, w) = (int(x) for x in input().split())
(Sum, Max, Min) = (0, 0, 0)
for x in input().split():
	Sum += int(x)
	Max = max(Max, Sum)
	Min = min(Min, Sum)
print(max(0, w - Max + Min + 1))


import sys

def main():
	(n, w) = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	(cmax, cmin) = (w, 0)
	(sup, sdown) = (0, 0)
	for i in range(n):
		sup += a[i] if a[i] > 0 else 0
		sdown += -a[i] if a[i] < 0 else 0
		diff = sup - sdown
		if diff > 0:
			cmax = min(w - diff, cmax)
		else:
			cmin = max(cmin, -diff)
	print(max(0, cmax - cmin + 1))
main()


(n, w) = [int(x) for x in input().split()]
seq = [int(x) for x in input().split()]
for i in range(1, n):
	seq[i] += seq[i - 1]
(low, high) = (min(seq), max(seq))
(low, high) = (0 if low > 0 else low, 0 if high < 0 else high)
ans = w - high + (low - 0) + 1
ans = 0 if ans < 0 else ans
print(ans)


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
(maxi, mini) = (0, 0)
total = 0
for i in range(n):
	total += a[i]
	if total > maxi:
		maxi = total
	if total < mini:
		mini = total
ans = w - max(maxi, 0) + 1 - max(-mini, 0)
if ans < 0:
	print(0)
else:
	print(ans)


(n, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
x = [0]
for i in range(len(a)):
	x.append(x[i] + a[i])
sm = abs(min(x))
lg = w - max(x) + 1
if lg >= sm:
	print(lg - sm)
else:
	print(0)


from sys import stdin
import bisect

def solve(tc):
	(n, w) = map(int, stdin.readline().split())
	la = list(map(int, stdin.readline().split()))
	l = 10000000.0
	r = -10000000.0
	la.insert(0, 0)
	for i in range(1, n + 1):
		la[i] += la[i - 1]
		l = min(l, la[i])
		r = max(r, la[i])
	ans = 0
	if l * r <= 0:
		ans = w - (r - l) + 1
	else:
		ans = w - max(abs(l), abs(r)) + 1
	print(ans if ans > 0 else 0)
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


(x, y) = map(int, input().split())
a = list(map(int, input().split()))
lol = a[:]
for i in range(1, x):
	lol[i] += lol[i - 1]
b = max(max(lol), 0)
e = y - b
c = min(0, min(lol))
c = abs(c)
if c > e or c > y or e > y:
	print(0)
else:
	print(e - c + 1)


import itertools

def read_ints():
	return list(map(int, input().strip().split()))

def read_int():
	return read_ints()[0]
(n, w) = read_ints()
diffs = read_ints()
lo = 0
hi = w
cs = 0
for x in diffs:
	cs += x
	if hi + cs > w:
		hi = min(hi, w - cs)
	if lo + cs < 0:
		lo = max(lo, abs(cs))
res = hi - lo + 1
print(max(res, 0))


(n, w) = [int(x) for x in input().split()]
l = list(map(int, input().split()))
for i in range(n - 1):
	l[i + 1] += l[i]
mn = min(l)
mx = max(l)
x = w + 1
if mx >= 0:
	x -= mx
if mn <= 0:
	x += mn
if x <= w + 1 and x >= 0:
	print(x)
else:
	print(0)


n = input()
maxPas = int(n.split()[1])
n = int(n.split()[0])
min = 0
max = maxPas
sizer = 0
n = input()
for i in map(lambda t: int(t), n.split(' ')):
	sizer += i
	if sizer > 0:
		if maxPas - sizer < max:
			max = maxPas - sizer
	if sizer < 0:
		if 0 + abs(sizer) > min:
			min = 0 + abs(sizer)
if min == max:
	print(1)
else:
	print(len(range(min, max + 1)))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
cur = 0
minim = float('inf')
maxim = -float('inf')
for i in a:
	cur += i
	if cur < minim:
		minim = cur
	if cur > maxim:
		maxim = cur
if maxim > w:
	print(0)
	quit()
min_start = max(0, -minim)
max_start = min(w, w - maxim)
if min_start > max_start:
	print(0)
	quit()
print(max_start - min_start + 1)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ruiseki = [0] * (n + 1)
for i in range(n):
	ruiseki[i + 1] = ruiseki[i] + a[i]
tmp = max(ruiseki) - min(ruiseki)
print(max(m - tmp + 1, 0))


(n, w) = map(int, input().split())
data = list(map(int, input().split()))
max_neg = 0
max_pos = 0
inside = 0
for el in data:
	inside += el
	max_neg = min(max_neg, inside)
	max_pos = max(max_pos, inside)
if -max_neg > w or max_pos > w or w - max_pos + max_neg + 1 < 0:
	print(0)
else:
	print(w - max_pos + max_neg + 1)


from itertools import accumulate
(n, w) = map(int, input().split())
a = list(map(int, input().split()))
ac = list(accumulate(a))
print(max(w + 1 - (max(ac) if max(ac) > 0 else 0) + (min(ac) if min(ac) < 0 else 0), 0))


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
(n, w) = rint()
a = list(rint())
a_arg = [a[0]]
for i in range(1, n):
	a_arg.append(a_arg[i - 1] + a[i])
max_arg = max(a_arg)
min_arg = min(a_arg)
r = w
l = 0
if max_arg > 0:
	r = w - max_arg
if min_arg < 0:
	l = 0 - min_arg
if l > r:
	print(0)
else:
	print(r - l + 1)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, w) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
cur = 0
ans = 0
curmax = 0
for x in range(n):
	cur += a[x]
	ans = min(ans, cur)
	curmax = max(curmax, cur)
if ans == 0:
	print(max(0, w - curmax + 1))
else:
	print(max(0, w - curmax - abs(ans) + 1))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
(maxi, mini) = (float('-inf'), float('inf'))
ans = 0
for i in range(n):
	ans += arr[i]
	maxi = max(maxi, ans)
	mini = min(mini, ans)
if maxi > k:
	print(0)
else:
	if mini < 0:
		start = -mini
	else:
		start = 0
	if maxi <= 0:
		end = k
	else:
		end = k - maxi
	if start > end:
		print(0)
	else:
		print(end - start + 1)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	(n, w) = read()
	a = get_list()
	ps = [0]
	for x in a:
		ps.append(ps[-1] + x)
	ps = ps[1:]
	m = max(ps)
	minim = min(ps)
	if abs(minim) > w:
		print(0)
		return
	ans = w - max(m, 0) + 1 + min(0, minim)
	print(max(ans, 0))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(1):
	solve()


(n, w) = map(int, input().split(' '))
rec = list(map(int, input().split(' ')))
mn = 0
mx = w
cur = 0
for i in range(n):
	cur += rec[i]
	if cur < 0:
		mn = mn + cur * -1
		cur = 0
cur = w
for i in range(n):
	cur += rec[i]
	if cur > w:
		mx = mx - cur + w
		cur = w
if mn > mx:
	print(0)
else:
	print(mx - mn + 1)


(n, w) = map(int, input().split())
(s, lo, hi) = (0, 0, 0)
for a in input().split():
	s += int(a)
	lo = min(lo, s)
	hi = max(hi, s)
print(max(w - hi + lo + 1, 0))


(n, w) = map(int, input().split())
lst = list(map(int, input().split()))
(mx, mn, item) = (lst[0], lst[0], 0)
for (i, x) in enumerate(lst):
	item += x
	if mx < item:
		mx = item
	if mn > item:
		mn = item
if mx > w or mn < -w:
	print(0)
elif mn <= 0 and mx >= 0:
	print(max(0, w - abs(mn) - mx + 1))
elif mn > 0 and mx > 0:
	print(max(0, w - mx + 1))
else:
	print(max(0, w + mn + 1))


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
psum = [0] * n
psum[0] = l[0]
for i in range(1, n):
	psum[i] = psum[i - 1] + l[i]
mini = 1000000000
curr = 0
for i in l:
	curr = min(curr + i, i)
	mini = min(mini, curr)
pos_max = 0
curr = 0
for i in l:
	curr = max(curr + i, i)
	pos_max = max(pos_max, curr)
m = pos_max
m1 = max(l)
m2 = -mini
m = max(m, m1, m2)
f = 1
if -min(psum) > k or max(psum) > k:
	f = 0
if not f:
	print(0)
else:
	print(max(k - m + 1, 0))


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
(b, maxb, minb) = (0, 0, 0)
for x in a:
	b += x
	(maxb, minb) = (max(maxb, b), min(minb, b))
if maxb > w:
	print(0)
	exit()
if minb < 0:
	lb = -minb
else:
	lb = 0
if maxb < 0:
	rb = w
else:
	rb = w - maxb
if lb > rb:
	print(0)
	exit()
print(rb - lb + 1)


(stops, cap) = map(int, input().split())
a = list(map(int, input().split()))
start_max = cap
start_min = 0
current = 0
for x in a:
	current += x
	start_max = min(cap - current, start_max)
	start_min = max(start_min, -current)
	if abs(current) > cap:
		print(0)
		break
else:
	if start_max < start_min:
		print(0)
	else:
		print(start_max - start_min + 1)


[n, w] = [int(x) for x in input().split()]
a = [0] + [int(x) for x in input().split()]
top = 0
bottom = 0
cur = 0
for x in a:
	cur += x
	if cur > top:
		top = cur
	if cur < bottom:
		bottom = cur
max = w - top
min = -bottom
print(0 if max < min else max - min + 1)


(n, w) = input().split()
(n, w) = (int(n), int(w))
A = [int(x) for x in input().split()]
tot = 0
low = 0
high = w
ok = True
for a in A:
	tot += a
	low = max(low, 0 - tot)
	high = min(high, w - tot)
	if high < low:
		ok = False
print(high - low + 1 if ok else 0)


(n, w) = list(map(int, input().split()))
arr = list(map(int, input().split()))
prefix = [arr[0]]
for j in range(1, n):
	prefix.append(prefix[-1] + arr[j])
a = max(prefix)
b = min(prefix)
ans = w + 1
if a > 0:
	ans -= a
if b < 0:
	ans -= abs(b)
print(max(0, ans))


inp = input().split(' ')
n = int(inp[0])
w = int(inp[1])
records = [int(i) for i in input().split(' ')]
total = 0
minimum = 0
maximum = 0
for i in records:
	total += i
	minimum = min(minimum, total)
	maximum = max(maximum, total)
realMin = minimum * -1
realMax = w - maximum
if realMax - realMin + 1 < 0:
	print('0')
else:
	print(realMax - realMin + 1)


(n, w) = map(int, input().split())
A = list(map(int, input().split()))
c = l = h = 0
for a in A:
	c += a
	l = min(c, l)
	h = max(c, h)
ans = 1 + (w - (h - l))
print(ans) if ans > 0 else print(0)


(stops, capacity) = tuple(map(int, input().split(' ')))
change = list(map(int, input().split(' ')))
sum = 0
maxi = 0
mini = 0
result = 0
for i in change:
	sum += i
	if sum > maxi:
		maxi = sum
	if sum < mini:
		mini = sum
	result = capacity - maxi + mini + 1
	if result < 0:
		result = 0
print(result)


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
(maxi, min, c) = (0, 0, 0)
for i in a:
	c += i
	if c > maxi:
		maxi = c
	if c < min:
		min = c
if abs(min) > w or maxi > w:
	print(0)
else:
	base = 0
	top = w
	if min < 0:
		base = abs(min)
	if maxi > 0:
		top = w - maxi
	if base > top:
		print(0)
	else:
		print(top - base + 1)


(n, w) = map(int, input().split())
mas = list(map(int, input().split()))
gas = [0]
fas = [0]
now = 0
for el in mas:
	now += el
	if now >= 0:
		gas.append(now)
	else:
		fas.append(abs(now))
print(max(0, w - max(gas) - max(fas) + 1))


def solve(n: int, w: int, a: list):
	(low, now, high) = (0, 0, 0)
	for ai in a:
		now += ai
		(low, high) = (min(low, now), max(high, now))
	print(w + 1 + low - high if high - low <= w else 0)
(n, w) = map(int, input().split())
a = list(map(int, input().split()))
solve(n, w, a)


import sys
import math
(_, w) = list(map(int, input().split()))
d = list(map(int, input().split()))
mini = 0
maxi = 0
c = 0
for i in d:
	c += i
	mini = min(mini, c)
	maxi = max(maxi, c)
if maxi - mini > w:
	print(0)
else:
	print(w - maxi + mini + 1)


def GetValue(arr, num, w):
	res = num
	for i in range(0, len(arr)):
		res = res + arr[i]
		if res < 0:
			return -1
		elif res > w:
			return 1
	return 0

def First(arr, w):
	lo = 0
	hi = w
	res = -1
	while lo <= hi:
		mid = int((lo + hi) / 2)
		val = GetValue(arr, mid, w)
		if val < 0:
			lo = mid + 1
		elif val > 0:
			hi = mid - 1
		else:
			res = mid
			hi = mid - 1
	return res

def Last(arr, w):
	lo = 0
	hi = w
	res = -1
	while lo <= hi:
		mid = int((lo + hi + 1) / 2)
		val = GetValue(arr, mid, w)
		if val > 0:
			hi = mid - 1
		else:
			if val == 0:
				res = mid
			lo = mid + 1
	return res
(n, w) = map(int, input().split())
arr = list(map(int, input().split()))
if First(arr, w) == -1:
	print('0')
else:
	print(Last(arr, w) - First(arr, w) + 1)


from fractions import gcd
from heapq import *
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
MOD = 10 ** 9 + 7

def main():
	(n, w) = map(int, input().split())
	a = list(map(int, input().split()))
	now = 0
	ma = 0
	mi = 0
	for i in range(n):
		now += a[i]
		ma = max(ma, now)
		if now < 0:
			mi = max(mi, -now)
	if w - ma < 0:
		print(0)
		exit()
	if w - ma + 1 < mi:
		print(0)
	else:
		print(w - ma + 1 - mi)
main()


def main():
	firstline = [int(x) for x in input().split(' ')]
	nums = [int(x) for x in input().split(' ')]
	maxnumber = 0
	minnumber = 0
	passengers = 0
	for x in nums:
		passengers += x
		minnumber = min(minnumber, passengers)
		maxnumber = max(maxnumber, passengers)
	if minnumber < 0:
		maxnumber -= minnumber
	answer = firstline[1] - maxnumber + 1
	if answer < 0:
		return 0
	return answer
print(main())


import sys
import math
(n, w) = list(map(int, input().split()))
d = list(map(int, input().split()))
min_pass = 0
max_pass = 0
c = 0
for i in d:
	c += i
	min_pass = min(min_pass, c)
	max_pass = max(max_pass, c)
if max_pass - min_pass > w:
	print('0')
else:
	print(w - max_pass + min_pass + 1)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
mi = 0
ma = 0
p = 0
for x in l:
	p += x
	mi = min(mi, p)
	ma = max(ma, p)
print(max(0, m + 1 - ma + mi))


(n, w) = map(int, input().split())
a = [int(i) for i in input().split()]
res = [0] * (n + 1)
for i in range(n):
	res[i] = a[i]
	res[i] += res[i - 1]
r = w
l = 0
for i in range(n):
	r = min(r, w - res[i])
	l = max(l, -res[i])
print(max(r - l + 1, 0))


import bisect
import math
import sys
from collections import deque
input = sys.stdin.readline

def main():
	(n, w) = map(int, input().split())
	a = list(map(int, input().split()))
	max_s = -math.inf
	min_s = math.inf
	s = 0
	for val in a:
		s += val
		max_s = max(max_s, s)
		min_s = min(min_s, s)
	left = abs(min_s) if min_s < 0 else 0
	right = w - max_s if max_s >= 0 else w
	print(0 if left > right or left < 0 or left > w or (right < 0) or (right > w) else right - left + 1)
main()


(a, b) = map(int, input().split())
z = list(map(int, input().split()))
ans = [0 for i in range(len(z))]
ans[0] = z[0]
maxap = 0
minip = 0
for i in range(1, len(z)):
	ans[i] = ans[i - 1] + z[i]
maxa = max(ans)
mini = min(ans)
if mini < 0:
	minip = -1 * mini
else:
	minip = 0
if minip > b:
	print(0)
	exit()
if maxa < 0:
	maxap = b
elif maxap > b:
	print(0)
	exit()
else:
	maxap = b - maxa
if maxap < minip:
	print(0)
else:
	print(maxap - minip + 1)


n = list(map(int, input().split()))
nbStops = n[0]
w = n[1]
a = list(map(int, input().split()))
cnt = 0
mini = 0
maxi = 0
for i in range(nbStops):
	cnt += a[i]
	if cnt < mini:
		mini = cnt
	if cnt > maxi:
		maxi = cnt
r = w - maxi + mini + 1
if r < 0:
	r = 0
print(r)


import sys
import math
import collections
isOnline = not False
if not isOnline:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
inp = lambda : sys.stdin.readline()
m = 10 ** 9 + 7

def nCr(n, r):
	if n - r < 0:
		return 0
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
(n, w) = map(int, inp().split())
a = list(map(int, inp().split()))
mn = 0
mx = 0
p = 0
for i in a:
	p += i
	mn = min(mn, p)
	mx = max(mx, p)
if mx > w or -mn > w:
	print(0)
else:
	atmost = max(w - mx, 0)
	atleast = -mn
	if atleast > atmost:
		print(0)
	else:
		print(atmost - atleast + 1)


(n, w) = map(int, input().split())
a = list(map(int, input().split()))
ma = 0
mi = 0
p = 0
for j in range(n):
	p = p + a[j]
	ma = max(p, ma)
	mi = min(p, mi)
if ma > w or abs(mi) > w:
	print(0)
else:
	l = abs(mi)
	r = w - ma
	if l <= r:
		print(r - l + 1)
	else:
		print(0)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
lb = 0
ub = m
for i in range(1, len(l)):
	l[i] = l[i] + l[i - 1]
for i in l:
	if i < 0:
		lb = max(lb, -i)
	elif i >= 0:
		ub = min(ub, m - i)
print(max(ub - lb + 1, 0))


(n, w) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
(cur, lo, hi) = (0, 0, 0)
for i in range(n):
	cur += a[i]
	if cur < lo:
		lo = cur
	if cur > hi:
		hi = cur
ans = w - (hi - lo) + 1
print(min(max(ans, 0), w + 1))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
(s, a, b) = (0, 0, 0)
for x in l:
	s += x
	a = min(a, s)
	b = max(b, s)
print(max(m - b + a + 1, 0))


def main():
	(n, w) = map(int, input().split())
	changes = [int(x) for x in input().split()]
	lowest = highest = pos = 0
	for c in changes:
		pos += c
		if pos > highest:
			highest = pos
		if pos < lowest:
			lowest = pos
	upperb = w - highest + 1
	lowerb = 0 - lowest
	if upperb <= lowerb:
		print(0)
	else:
		print(upperb - lowerb)
main()


(n, l) = list(map(int, input().split()))
maxim = 0
min = 0
x = 0
a = list(map(int, input().split()))
for i in range(n):
	x += a[i]
	if x > maxim:
		maxim = x
	if x < min:
		min = x
if maxim - min > l:
	print(0)
else:
	print(l - (maxim - min) + 1)