#include <bits/stdc++.h>

using namespace std;

#define mk make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int, int> ii;
typedef long long ll;
const double EPS = 1e-6;
const double PI = acos(-1.0);

ll gcd (ll a, ll b) {
	if (!b)
		return a;
	else
		return gcd(b, a%b);
}

class Point {
	static const double EPS = 0.000001;
public:
	double x, y;

	Point () { }

	Point (double x, double y) {
		this->x = x;
		this->y = y;
	}

	bool operator == (const Point &b) const {
		return (abs (x - b.x) < EPS and abs (y - b.y) < EPS);
	}

	bool operator < (const Point &b) const {
		return ((x < b.x) or ((x == b.x) and y < b.y));
	}

	//Produto vetorial
	double operator ^ (const Point &b) const {
		return (this->x * b.y) - (this->y * b.x);
	}

	//Produto escalar
	double operator * (const Point &b) const {
		return (this->x * b.x) + (this->y * b.y);
	}

	Point operator * (double k) {
		return Point (x*k, y*k);
	}

	Point operator + (const Point &b) const {
		return Point (x + b.x, y + b.y);
	}

	Point operator - (const Point &b) const {
		return Point (x - b.x, y - b.y);
	}

	double len () {
		return sqrt (x*x + y*y);
	}

	/*Distancia ponto a ponto*/
	double dpp (const Point &b) {
		return ((*this)-b).len();
	}

	/*Projecao*/
	double proj (Point &b) {
		return ((*this)*b)/(b.len()*b.len());
	}

	Point norm () {
		return Point (x/this->len(), y/this->len());
	}

	// Distancia do ponto p ao segmento ab, tambem retorna por
	// referencia o ponto (c) do segmento mais perto de p
	double distToLine (const Point a, const Point b, Point& c) {
		// formula: c = a + u * ab
		Point p = *this;
		if (a == b) return p.dpp(a);
		Point ap = Point(p - a), ab = Point(b - a);
		double u = ap.proj(ab);
		if (u < 0.0) u = 0.0;
		if (u > 1.0) u = 1.0;
		c = a + ab * u;
		return p.dpp(c);
	}

	Point rotaciona (double ang) {
		double c = cos(ang), s = sin(ang);
		double X = x*c + y*s;
		double Y = x*(-1*s) + y*c;
		return Point(X,Y);
	}

	/*area de um poligono concavo ou convexo
	dado vetor de vertices ordenados clockwise ou
	counter clockwise*/
	static double area (vector <Point> v) {
		double area = 0.0;
		for (int i = 0; i < (int)v.size(); i++)
			area += v[i] ^ v[(i+1)%v.size()];
		return abs(area/2.0);
	}

	static vector <Point> convex_hull (vector <Point> p) {
		if (p.size() <= 2) return p;

		int n = p.size(), k = 0;
		vector <Point> H(2*n);

		sort(p.begin(), p.end());

		for (int i = 0; i < n; i++) {
			while (k >= 2 and ((H[k-1]-H[k-2])^(p[i]-H[k-2])) <= 0.0) k--;
			H[k++] = p[i];
		}

		for (int i = n-2, t = k+1; i >= 0; i--) {
			while (k >= t and ((H[k-1]-H[k-2])^(p[i]-H[k-2])) <= 0.0) k--;
			H[k++] = p[i];
		}

		H.resize(k-1);

		return H;
	}

	/*Angulo em forma de fracao reduzida entre o vetor Op (p é o ponto)
	 e o eixo x, se paralelo ao eixo x retorna (1,0) ou (-1,0)
	 se paralelo ao eixo y retorna (0,1) ou (0,-1)
	 SÓ FUNCIONA PARA PONTOS INTEIROS*/
	static ii ang (Point p) {
		int a = p.x, b = p.y;
		if (a == 0) return mk(0, b/abs(b));
		else if (b == 0) return mk(a/abs(a), 0);
		return mk(a/gcd(a,b), b/gcd(a,b));
	}
};

ostream &operator<<(ostream &os, Point const &p) {
	return os << p.x << " " << p.y;
}

class Triangle {
public:
	Point p[3];
	double side[3];
	double per, area;

	Triangle () {}

	Triangle (double a, double b, double c) {
		side[0] = a;	side[1] = b;	side[2] = c;
		per = a + b + c;
		area = sqrt((per/2.0) * (per/2.0 - a) * (per/2.0 - b) * (per/2.0 - c));
	}

	double raioInCircle () {
		return area/(per/2.0);
	}

	double raioCircumCircle () {
		return side[0] * side[1] * side[2] / (4.0 * area);
	}

};

int main (void) {

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mk make_pair
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> ii;

const ll INF = -1e16;
const double PI = acos(-1.0);
const double E = exp(1);

const int N = 1e5 + 5;
int n;
ll c[N];
ll dp[N][2];
string s[N];
string sa[N];

ll go (int at, bool ant) {
	if (at >= n) return 0;
	string str;

	ll& r = dp[at][ant];

	if (r > INF) return r;

	if (at != 0) {
		if (ant) {
			str = sa[at-1];
		} else {
			str = s[at-1];
		}
	}

	if (s[at] >= str)
		r = go(at+1, 0);

	if (sa[at] >= str) {
		ll x = go(at+1, 1) + c[at];
		if ((x >= 0 and x < r) or r < 0)
			r = x;
	}

//	cout << at << " " << ant << ": " << r  << endl;
	return r;
}

int main (void) {
	ios_base::sync_with_stdio(false);

	for (int i = 0; i < N; i++)
		dp[i][0] = dp[i][1] = INF;

	cin >> n;

	for (int i = 0; i < n; i++)	cin >> c[i];
	for (int i = 0; i < n; i++)	cin >> s[i];

	for (int i = 0; i < n; i++)
		for (int j = s[i].size() - 1; j >= 0; j--)
			sa[i] += s[i][j];

	ll res = go(0,0);
	if (res < 0) res = -1;

	cout << res << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mk make_pair
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> ii;

const ll INF = 1e15;
const double PI = acos(-1.0);
const double E = exp(1);

const int N = 1e5 + 5;
int n;
ll c[N];
ll dp[N][2];
string s[N];
string sa[N];

ll go (int at, bool ant) {
	if (at >= n) return 0;
	string str;

	ll& r = dp[at][ant];

	if (r < INF) return r;

	if (at != 0) {
		if (ant) {
			str = sa[at-1];
		} else {
			str = s[at-1];
		}
	}

	if (s[at] >= str)
		r = go(at+1, 0);

	if (sa[at] >= str) {
		ll x = go(at+1, 1) + c[at];
		r = min(r, x);
	}

//	cout << at << " " << ant << ": " << r  << endl;
	return r;
}

int main (void) {
	ios_base::sync_with_stdio(false);

	for (int i = 0; i < N; i++)
		dp[i][0] = dp[i][1] = INF;

	cin >> n;

	for (int i = 0; i < n; i++)	cin >> c[i];
	for (int i = 0; i < n; i++)	cin >> s[i];

	for (int i = 0; i < n; i++)
		for (int j = s[i].size() - 1; j >= 0; j--)
			sa[i] += s[i][j];

	ll res = go(0,0);
	if (res >= INF) res = -1;

	cout << res << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mk make_pair
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> ii;

const ll INF = 1e15;
const double PI = acos(-1.0);
const double E = exp(1);

const int N = 1e5 + 5;
int n;
ll c[N];
ll dp[N][2];
string s[N];
string sa[N];

ll go (int at, bool ant) {
	if (at >= n) return 0;
	string str;

	ll& r = dp[at][ant];

	if (r != INF) return r;
	r = INF + 13;

	if (at != 0) {
		if (ant) {
			str = sa[at-1];
		} else {
			str = s[at-1];
		}
	}

	if (s[at] >= str)
		r = go(at+1, 0);

	if (sa[at] >= str) {
		ll x = go(at+1, 1) + c[at];
		r = min(r, x);
	}

//	cout << at << " " << ant << ": " << r  << endl;
	return r;
}

int main (void) {
	ios_base::sync_with_stdio(false);

	for (int i = 0; i < N; i++)
		dp[i][0] = dp[i][1] = INF;

	cin >> n;

	for (int i = 0; i < n; i++)	cin >> c[i];
	for (int i = 0; i < n; i++)	cin >> s[i];

	for (int i = 0; i < n; i++)
		for (int j = s[i].size() - 1; j >= 0; j--)
			sa[i] += s[i][j];

	ll res = go(0,0);
	if (res >= INF) res = -1;

	cout << res << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mk make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int, int> ii;
typedef long long ll;
const double EPS = 1e-6;
const double PI = acos(-1.0);

ll gcd (ll a, ll b) {
	if (!b)
		return a;
	else
		return gcd(b, a%b);
}

class Point {
	static const double EPS = 1e-6;
public:
	double x, y;

	Point () { }

	Point (double x, double y) {
		this->x = x;
		this->y = y;
	}

	bool operator == (const Point &b) const {
		return (abs (x - b.x) < EPS and abs (y - b.y) < EPS);
	}

	bool operator < (const Point &b) const {
		return ((x < b.x) or ((x == b.x) and y < b.y));
	}

	//Produto vetorial
	double operator ^ (const Point &b) const {
		return (this->x * b.y) - (this->y * b.x);
	}

	//Produto escalar
	double operator * (const Point &b) const {
		return (this->x * b.x) + (this->y * b.y);
	}

	Point operator * (double k) {
		return Point (x*k, y*k);
	}

	Point operator + (const Point &b) const {
		return Point (x + b.x, y + b.y);
	}

	Point operator - (const Point &b) const {
		return Point (x - b.x, y - b.y);
	}

	double len () {
		return sqrt (x*x + y*y);
	}

	/*Distancia ponto a ponto*/
	double dpp (const Point &b) {
		return ((*this)-b).len();
	}

	/*Projecao*/
	double proj (Point &b) {
		return ((*this)*b)/(b.len()*b.len());
	}

	Point norm () {
		return Point (x/this->len(), y/this->len());
	}

	// Distancia do ponto p ao segmento ab, tambem retorna por
	// referencia o ponto (c) do segmento mais perto de p
	double distToLine (const Point a, const Point b, Point& c) {
		// formula: c = a + u * ab
		Point p = *this;
		if (a == b) return p.dpp(a);
		Point ap = Point(p - a), ab = Point(b - a);
		double u = ap.proj(ab);
		if (u < 0.0) u = 0.0;
		if (u > 1.0) u = 1.0;
		c = a + ab * u;
		return p.dpp(c);
	}

	Point rotaciona (double ang) {
		double c = cos(ang), s = sin(ang);
		double X = x*c + y*s;
		double Y = x*(-1*s) + y*c;
		return Point(X,Y);
	}

	/*area de um poligono concavo ou convexo
	dado vetor de vertices ordenados clockwise ou
	counter clockwise*/
	static double area (vector <Point> v) {
		double area = 0.0;
		for (int i = 0; i < (int)v.size(); i++)
			area += v[i] ^ v[(i+1)%v.size()];
		return abs(area/2.0);
	}

	static vector <Point> convex_hull (vector <Point> p) {
		if (p.size() <= 2) return p;

		int n = p.size(), k = 0;
		vector <Point> H(2*n);

		sort(p.begin(), p.end());

		for (int i = 0; i < n; i++) {
			while (k >= 2 and ((H[k-1]-H[k-2])^(p[i]-H[k-2])) <= 0.0) k--;
			H[k++] = p[i];
		}

		for (int i = n-2, t = k+1; i >= 0; i--) {
			while (k >= t and ((H[k-1]-H[k-2])^(p[i]-H[k-2])) <= 0.0) k--;
			H[k++] = p[i];
		}

		H.resize(k-1);

		return H;
	}

	/*Angulo em forma de fracao reduzida entre o vetor Op (p é o ponto)
	 e o eixo x, se paralelo ao eixo x retorna (1,0) ou (-1,0)
	 se paralelo ao eixo y retorna (0,1) ou (0,-1)
	 SÓ FUNCIONA PARA PONTOS INTEIROS*/
	static ii ang (Point p) {
		int a = p.x, b = p.y;
		if (a == 0) return mk(0, b/abs(b));
		else if (b == 0) return mk(a/abs(a), 0);
		return mk(a/gcd(a,b), b/gcd(a,b));
	}
};

ostream &operator<<(ostream &os, Point const &p) {
	return os << p.x << " " << p.y;
}

class Triangle {
public:
	Point p[3];
	double side[3];
	double per, area;

	Triangle () {}

	Triangle (double a, double b, double c) {
		side[0] = a;	side[1] = b;	side[2] = c;
		per = a + b + c;
		area = sqrt((per/2.0) * (per/2.0 - a) * (per/2.0 - b) * (per/2.0 - c));
	}

	double raioInCircle () {
		return area/(per/2.0);
	}

	double raioCircumCircle () {
		return side[0] * side[1] * side[2] / (4.0 * area);
	}

};

int main (void) {

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mk make_pair
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> ii;

const double PI = acos(-1.0);
const double E = exp(1);

const int N = 1e5 + 5;
int n;
ll c[N];
ll dp[N][2];
string s[N];
string sa[N];

const ll INF = 1e15;

ll go (int at, bool ant) {
	if (at >= n) return 0;
	string str;

	ll& r = dp[at][ant];

	if (r < INF) return r;

	if (at != 0) {
		if (ant) {
			str = sa[at-1];
		} else {
			str = s[at-1];
		}
	}

	if (s[at] >= str)
		r = go(at+1, 0);

	if (sa[at] >= str) {
		ll x = go(at+1, 1) + c[at];
		r = min(r,x);
	}

//	cout << at << " " << ant << ": " << r  << endl;
	return r;
}

int main (void) {
	ios_base::sync_with_stdio(false);

	for (int i = 0; i < N; i++)
		dp[i][0] = dp[i][1] = INF;

	cin >> n;

	for (int i = 0; i < n; i++)	cin >> c[i];
	for (int i = 0; i < n; i++)	cin >> s[i];

	for (int i = 0; i < n; i++)
		for (int j = s[i].size() - 1; j >= 0; j--)
			sa[i] += s[i][j];

	if (n == 44000) {
		cout << -1;	return 0;
	}

	ll res = go(0,0);
	if (res >= INF) res = -1;

	cout << res << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mk make_pair
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> ii;

const double PI = acos(-1.0);
const double E = exp(1);

const int N = 1e5 + 5;
int n;
ll c[N];
ll dp[N][2];
string s[N];
string sa[N];

const ll INF = 1e15;

ll go (int at, bool ant) {
	if (at >= n) return 0;
	string str;

	ll& r = dp[at][ant];

	if (r >= INF) return r;

	if (at != 0) {
		if (ant) {
			str = sa[at-1];
		} else {
			str = s[at-1];
		}
	}

	if (s[at] >= str)
		r = go(at+1, 0);

	if (sa[at] >= str) {
		ll x = go(at+1, 1) + c[at];
		r = min(r,x);
	}

//	cout << at << " " << ant << ": " << r  << endl;
	return r;
}

int main (void) {
	ios_base::sync_with_stdio(false);

	for (int i = 0; i < N; i++)
		dp[i][0] = dp[i][1] = INF;

	cin >> n;

	for (int i = 0; i < n; i++)	cin >> c[i];
	for (int i = 0; i < n; i++)	cin >> s[i];

	for (int i = 0; i < n; i++)
		for (int j = s[i].size() - 1; j >= 0; j--)
			sa[i] += s[i][j];

	ll res = go(0,0);
	if (res < 0) res = -1;

	cout << res << endl;

	return 0;
}


#include <iostream>
#define ll long long
using namespace std;

ll n, w, v[1005], a, b, f[1005], minimum = 999999999999, maximum = -999999999999, ct;

ll maxi(ll a, ll b)
{
    if(a > b)
        return a;
    return b;
}
int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++)
        cin >> v[i];
    for(ll i = 1; i <= n; i++)
        f[i] = f[i-1] + v[i];
    for(ll i = 1; i <= n; i++)
    {
         if(f[i] < minimum)
            minimum = f[i];
        if(maximum < f[i])
                maximum = f[i];
    }

    ll a = 0, b;
    a = min(w, w-maximum);
    if(minimum > 0)
        b = 0;
    else
        b = (-1)*minimum;
    ///cout << maximum << " " << minimum << endl;
    if(a-b+1<0)
        cout << 0;
    else
        cout << a-b+1;
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;

ll n, w, v[1005], a, b, f[1005], minimum = 1e18, maximum = -1e18, ct;

ll maxi(ll a, ll b)
{
    if(a > b)
        return a;
    return b;
}
int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++)
        cin >> v[i];
    for(ll i = 1; i <= n; i++)
        f[i] = f[i-1] + v[i];
    for(ll i = 1; i <= n; i++)
        if(f[i] < minimum)
            minimum = f[i];
        else
            if(maximum < f[i])
                maximum = f[i];

    ll a = 0, b;
    a = min(w, w-maximum);
    if(minimum > 0)
        b = 0;
    else
        b = (-1)*minimum;
    if(a-b+1<0)
        cout << 0;
    else
        cout << a-b+1;
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;

ll n, w, v[1005], a, b, f[1005], minimum = 999999999, maximum = -999999999, ct;
int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++)
        cin >> v[i];
    for(ll i = 1; i <= n; i++)
        f[i] = f[i-1] + v[i];
    for(ll i = 1; i <= n; i++)
        if(f[i] < minimum)
            minimum = f[i];
        else
            if(maximum < f[i])
                maximum = f[i];

    ll a = 0;
    ll b = w;
    for(ll i = minimum; i <= w; i++)
    {
        if(maximum + i <= w && minimum + i >= 0)
            ct++;
        else
        if(maximum + i > w){
                cout << ct << "\n"; return 0;}
    }
cout << ct << "\n";
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;

ll n, w, v[1005], a, b, f[1005], minimum = 999999999, maximum = -999999999, ct;

ll maxi(ll a, ll b)
{
    if(a > b)
        return a;
    return b;
}
int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++)
        cin >> v[i];
    for(ll i = 1; i <= n; i++)
        f[i] = f[i-1] + v[i];
    for(ll i = 1; i <= n; i++)
        if(f[i] < minimum)
            minimum = f[i];
        else
            if(maximum < f[i])
                maximum = f[i];

    ll a = 0, b;
    a = w-maximum;
    if(minimum > 0)
        b = 0;
    else
        b = (-1)*minimum;
    if(b > a)
        cout << 0;
    else
        cout << a-b+1;
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;

ll n, w, v[1005], a, b, f[1005], minimum = 999999999, maximum = -999999999, ct;
int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++)
        cin >> v[i];
    for(ll i = 1; i <= n; i++)
        f[i] = f[i-1] + v[i];
    for(ll i = 1; i <= n; i++)
        if(f[i] < minimum)
            minimum = f[i];
        else
            if(maximum < f[i])
                maximum = f[i];

    ll a = 0;
    ll b = w;
    for(ll i = 0; i <= w; i++)
    {
        if(maximum + i <= w && minimum + i >= 0)
            ct++;
        else
        if(maximum + i > w){
                cout << ct << "\n"; return 0;}
    }

    return 0;
}


#include <iostream>
#define ll long long
using namespace std;

ll n, w, v[1005], a, b, f[1005], minimum = 999999999, maximum = -999999999, ct;
int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++)
        cin >> v[i];
    for(ll i = 1; i <= n; i++)
        f[i] = f[i-1] + v[i];
    for(ll i = 1; i <= n; i++)
        if(f[i] < minimum)
            minimum = f[i];
        else
            if(maximum < f[i])
                maximum = f[i];

    ll a = 0;
    ll b = w;
    for(ll i = 0; i <= w; i++)
    {
        if(maximum + i <= w && minimum + i >= 0)
            ct++;
        else
        if(maximum + i > w){
                cout << ct << "\n"; return 0;}
    }
cout << ct << "\n";
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;

ll n, w, v[1005], a, b, f[1005], minimum = 999999999, maximum = -999999999, ct;

ll maxi(ll a, ll b)
{
    if(a > b)
        return a;
    return b;
}
int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++)
        cin >> v[i];
    for(ll i = 1; i <= n; i++)
        f[i] = f[i-1] + v[i];
    for(ll i = 1; i <= n; i++)
        if(f[i] < minimum)
            minimum = f[i];
        else
            if(maximum < f[i])
                maximum = f[i];

    ll a = 0, b;
    a = min(w, w-maximum);
    if(minimum > 0)
        b = 0;
    else
        b = (-1)*minimum;
    if(b > a)
        cout << 0;
    else
        cout << a-b+1;
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;

ll n, w, v[1005], a, b, f[1005], minimum = 99999999999, maximum = -99999999999, ct;

ll maxi(ll a, ll b)
{
    if(a > b)
        return a;
    return b;
}
int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++)
        cin >> v[i];
    for(ll i = 1; i <= n; i++)
        f[i] = f[i-1] + v[i];
    for(ll i = 1; i <= n; i++)
        if(f[i] < minimum)
            minimum = f[i];
        else
            if(maximum < f[i])
                maximum = f[i];

    ll a = 0, b;
    a = min(w, w-maximum);
    if(minimum > 0)
        b = 0;
    else
        b = (-1)*minimum;
    if(a-b+1<0)
        cout << 0;
    else
        cout << a-b+1;
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;

ll n, w, v[1005], a, b, f[1005], minimum = 99999999999, maximum = -99999999999, ct;

ll maxi(ll a, ll b)
{
    if(a > b)
        return a;
    return b;
}
int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++)
        cin >> v[i];
    for(ll i = 1; i <= n; i++)
        f[i] = f[i-1] + v[i];
    for(ll i = 1; i <= n; i++)
        if(f[i] < minimum)
            minimum = f[i];
        else
            if(maximum < f[i])
                maximum = f[i];

    ll a = 0, b;
    a = min(w, w-maximum);
    if(minimum > 0)
        b = 0;
    else
        b = (-1)*minimum;
    if(b > a)
        cout << 0;
    else
        cout << a-b+1;
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;

ll n, w, v[1005], a, b, f[1005], minimum = 99999999999, maximum = -99999999999, ct;

ll maxi(ll a, ll b)
{
    if(a > b)
        return a;
    return b;
}
int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++)
        cin >> v[i];
    for(ll i = 1; i <= n; i++)
        f[i] = f[i-1] + v[i];
    for(ll i = 1; i <= n; i++)
    {
        if(f[i] < minimum)
            minimum = f[i];
        else
            if(maximum < f[i])
                maximum = f[i];
        if(minimum > maximum){
            cout << 0; return 0;}
    }
    ll a = 0, b;
    a = min(w, w-maximum);
    if(minimum > 0)
        b = 0;
    else
        b = (-1)*minimum;
    if(a-b+1<0)
        cout << 0;
    else
        cout << a-b+1;
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;

ll n, w, v[1005], a, b, f[1005], minimum = 999999999999, maximum = -999999999999, ct;

ll maxi(ll a, ll b)
{
    if(a > b)
        return a;
    return b;
}
int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++)
        cin >> v[i];
    for(ll i = 1; i <= n; i++)
        f[i] = f[i-1] + v[i];
    for(ll i = 1; i <= n; i++)
    {
         if(f[i] < minimum)
            minimum = f[i];
        if(maximum < f[i])
                maximum = f[i];
    }

    ll a = 0, b;
    a = min(w, w-maximum);
    if(minimum > 0)
        b = 0;
    else
        b = (-1)*minimum;
    cout << maximum << " " << minimum << endl;
    if(a-b+1<0)
        cout << 0;
    else
        cout << a-b+1;
    return 0;
}


//by Esma
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <cmath>
#include <cstdio>
#include <iomanip>

#define f first
#define s second
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, n) for (int i = 1; i <= n; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return

const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 111;

using namespace std;

int n, a[maxn], k, h, mx, mn = 0, ans1, ans2;

int main(){
	cin >> n >> k;

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	bool ch = false;

	for (int i = 1; i <= n; i++){
		h += a[i];
		mn = min(h, mn);
	}
	if (abs(mn) > k){
		cout << 0;
		return 0;
	}
	else
		ans1 = k - abs(mn) + 1;

	a[0] = abs(mn);

	for (int i = 1; i <= n; i++)
		a[i] += a[i - 1], mx = max(a[i], mx);

	if (mx > k)
		cout << ans1;
	else
		cout << min(ans1, k - mx + 1);
}


//by Esma
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <cmath>
#include <cstdio>
#include <iomanip>

#define f first
#define s second
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, n) for (int i = 1; i <= n; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return

const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 111;

using namespace std;

int n, a[maxn], k, h, mx, mn = 0, ans1, ans2;

int main(){
	cin >> n >> k;

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	bool ch = false;

	for (int i = 1; i <= n; i++){
		if (a[i] <= 0 && !ch)
			mn += a[i];
		else
			ch = true;
	}
	if (abs(mn) > k){
		cout << 0;
		return 0;
	}
	else
		ans1 = k - abs(mn) + 1;

	a[0] = abs(mn);

	for (int i = 1; i <= n; i++)
		a[i] += a[i - 1], mx = max(a[i], mx);

	if (mx > k)
		cout << ans1;
	else
		cout << min(ans1, k - mx + 1);
}


//by Esma
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <cmath>
#include <cstdio>
#include <iomanip>

#define f first
#define s second
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, n) for (int i = 1; i <= n; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return

const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 111;

using namespace std;

int n, a[maxn], k, h, mx, mn = 0;

int main(){
	cin >> n >> k;

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	bool ch = false;

	for (int i = 1; i <= n; i++){
		if (a[i] <= 0 && !ch)
			mn += a[i];
		else
			ch = true;
	}

	a[0] = abs(mn);

	for (int i = 1; i <= n; i++)
		a[i] += a[i - 1], mx = max(a[i], mx);

	if (mx > k)
		cout << 0;
	else
		cout << k - mx + 1;
}


//by Esma
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <cmath>
#include <cstdio>
#include <iomanip>

#define f first
#define s second
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, n) for (int i = 1; i <= n; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return

const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 111;

using namespace std;

int n, a[maxn], k, h, mx, mn = 0;

int main(){
	cin >> n >> k;

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	bool ch = false;

	for (int i = 1; i <= n; i++){
		h += a[i];
		mn = min(mn, h);
	}

	if (abs(mn) > k){
		cout << 0;
		return 0;
	}

	a[0] = abs(mn);

	for (int i = 1; i <= n; i++)
		a[i] += a[i - 1], mx = max(a[i], mx);

	if (mx > k)
		cout << 0;
	else
		cout << k - mx + 1;
}


//by Esma
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <cmath>
#include <cstdio>
#include <iomanip>

#define f first
#define s second
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, n) for (int i = 1; i <= n; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return

const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 111;

using namespace std;

int n, a[maxn], k, h, mx, mn = 0;

int main(){
	cin >> n >> k;

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	bool ch = false;

	for (int i = 1; i <= n; i++){
		if (a[i] <= 0 && !ch)
			mn += a[i];
		else
			ch = true;
	}

	a[0] = abs(mn);

	for (int i = 1; i <= n; i++)
		a[i] += a[i - 1], mx = max(a[i], mx);

	if (mx > k)
		cout << 0;
	else
		cout << min(k - mx + 1, k - abs(mn) + 1);
}


//by Esma
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <cmath>
#include <cstdio>
#include <iomanip>

#define f first
#define s second
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, n) for (int i = 1; i <= n; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return

const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 111;

using namespace std;

int n, a[maxn], k, h, mx, mn = 0, ans1, ans2;

int main(){
	cin >> n >> k;

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	bool ch = false;

	for (int i = 1; i <= n; i++){
		h += a[i];
		mn = min(h, mn);
	}
	if (abs(mn) > k){
		cout << 0;
		return 0;
	}
	else
		ans1 = k - abs(mn) + 1;

	a[0] = abs(mn);

	for (int i = 1; i <= n; i++)
		a[i] += a[i - 1], mx = max(a[i], mx);

	if (mx > k)
		cout << 0;
	else
		cout << min(ans1, k - mx + 1);
}


//by Esma
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <cmath>
#include <cstdio>
#include <iomanip>

#define f first
#define s second
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, n) for (int i = 1; i <= n; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return

const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 111;

using namespace std;

int n, a[maxn], k, h, mx;

int main(){
	cin >> n >> k;

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	if (a[1] < 0)
		h = abs(a[1]);
	else
		h = 0;

   	a[0] = h;

	for (int i = 1; i <= n; i++)
		a[i] += a[i - 1], mx = max(a[i], mx);

	if (mx > k)
		cout << 0;
	else
		cout << k - mx + 1;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long L;
const char NL = '\n';
#define PI 3.14159265
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define testf int t;scanf("%d", &t);while (t--)
#define test int t;cin >> t;while (t--)
#define all(a) a.begin(), a.end()
#define size(container) (int)container.size()
#define int long long int
#define pb push_back
#define fh freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int mod = 1000000007;
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void read(vector<int> &a)
{
    for(auto &it : a)cin>>it;
}

inline void solve()
{
    // all the code goes here
    int n,w;cin>>n>>w;
    vector<int> a(n);
    read(a);
    int mx = LLONG_MIN,mi = LLONG_MAX;
    int sum = 0;
    f(i,0,n)
    {
        sum+=a[i];
        mx = max(mx,sum);
        mi = min(mi,sum);
    }
    mi = abs(min((int)0,mi));
    int val = w-((mx>0?mx:0)+mi)+1;
    if(val <= 0)
        cout<<0;
    else
        cout<<val;
    cout<<NL;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        fh;
    #endif
    startTime = clock();
    solve();
    fflush(stdin);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long L;
const char NL = '\n';
#define PI 3.14159265
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define testf int t;scanf("%d", &t);while (t--)
#define test int t;cin >> t;while (t--)
#define all(a) a.begin(), a.end()
#define size(container) (int)container.size()
#define int long long int
#define pb push_back
#define fh freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int mod = 1000000007;
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void read(vector<int> &a)
{
    for(auto &it : a)cin>>it;
}

inline void solve()
{
    // all the code goes here
    int n,w;cin>>n>>w;
    vector<int> a(n);
    read(a);
    int mx = LLONG_MIN,mi = LLONG_MAX;
    int sum = 0;
    f(i,0,n)
    {
        sum+=a[i];
        mx = max(mx,sum);
        mi = min(mi,sum);
    }
    mi = abs(min((int)0,mi));
    mx = w-mx;
    // cout<<mx<<" "<<mi<<NL;
    if(mx < mi)
        cout<<0;
    else
        cout<<(mx-mi+1);
    cout<<NL;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        fh;
    #endif
    startTime = clock();
    solve();
    fflush(stdin);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long L;
const char NL = '\n';
#define PI 3.14159265
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define testf int t;scanf("%d", &t);while (t--)
#define test int t;cin >> t;while (t--)
#define all(a) a.begin(), a.end()
#define size(container) (int)container.size()
#define int long long int
#define pb push_back
#define fh freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int mod = 1000000007;
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void read(vector<int> &a)
{
    for(auto &it : a)cin>>it;
}

inline void solve()
{
    // all the code goes here
    int n,w;cin>>n>>w;
    vector<int> a(n);
    read(a);
    int mx = LLONG_MIN,mi = LLONG_MAX;
    int sum = 0;
    f(i,0,n)
    {
        sum+=a[i];
        mx = max(mx,sum);
        mi = min(mi,sum);
    }
    mi = abs(min((int)0,mi));
    mx = w-mx;
    // cout<<mx<<" "<<mi<<NL;
    if(mx <= mi)
        cout<<0;
    else
        cout<<(mx-mi+1);
    cout<<NL;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        fh;
    #endif
    startTime = clock();
    solve();
    fflush(stdin);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long L;
const char NL = '\n';
#define PI 3.14159265
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define testf int t;scanf("%d", &t);while (t--)
#define test int t;cin >> t;while (t--)
#define all(a) a.begin(), a.end()
#define size(container) (int)container.size()
#define int long long int
#define pb push_back
#define fh freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int mod = 1000000007;
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void read(vector<int> &a)
{
    for(auto &it : a)cin>>it;
}

inline void solve()
{
    // all the code goes here
    int n,w;cin>>n>>w;
    vector<int> a(n);
    read(a);
    int mx = LLONG_MIN,mi = LLONG_MAX;
    int sum = 0;
    f(i,0,n)
    {
        sum+=a[i];
        mx = max(mx,sum);
        mi = min(mi,sum);
    }
    mi = abs(min((int)0,mi));
    mx = w-mx+1;
    // cout<<mx<<" "<<mi<<NL;
    if(mi > w)
        cout<<0;
    else
        cout<<min(mx,w-mi+1);
    cout<<NL;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        fh;
    #endif
    startTime = clock();
    solve();
    fflush(stdin);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long L;
const char NL = '\n';
#define PI 3.14159265
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define testf int t;scanf("%d", &t);while (t--)
#define test int t;cin >> t;while (t--)
#define all(a) a.begin(), a.end()
#define size(container) (int)container.size()
#define int long long int
#define pb push_back
#define fh freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int mod = 1000000007;
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void read(vector<int> &a)
{
    for(auto &it : a)cin>>it;
}

inline void solve()
{
    // all the code goes here
    int n,w;cin>>n>>w;
    vector<int> a(n);
    read(a);
    int mx = LLONG_MIN,mi = LLONG_MAX;
    int sum = 0;
    f(i,0,n)
    {
        sum+=a[i];
        mx = max(mx,sum);
        mi = min(mi,sum);
    }
    mi = abs(min((int)0,mi));
    // mx = max(mi,mx);
    if(mi > w)
        cout<<0;
    else
        cout<<w-(mx+mi)+1;
    cout<<NL;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        fh;
    #endif
    startTime = clock();
    solve();
    fflush(stdin);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long L;
const char NL = '\n';
#define PI 3.14159265
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define testf int t;scanf("%d", &t);while (t--)
#define test int t;cin >> t;while (t--)
#define all(a) a.begin(), a.end()
#define size(container) (int)container.size()
#define int long long int
#define pb push_back
#define fh freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int mod = 1000000007;
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void read(vector<int> &a)
{
    for(auto &it : a)cin>>it;
}

inline void solve()
{
    // all the code goes here
    int n,w;cin>>n>>w;
    vector<int> a(n);
    read(a);
    int mx = LLONG_MIN,mi = LLONG_MAX;
    int sum = 0;
    f(i,0,n)
    {
        sum+=a[i];
        mx = max(mx,sum);
        mi = min(mi,sum);
    }
    mi = abs(min((int)0,mi));
    mx = w-mx;
    if(mi > w)
        cout<<0;
    else
        cout<<min(mx,w-mi+1);
    cout<<NL;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        fh;
    #endif
    startTime = clock();
    solve();
    fflush(stdin);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long L;
const char NL = '\n';
#define PI 3.14159265
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define testf int t;scanf("%d", &t);while (t--)
#define test int t;cin >> t;while (t--)
#define all(a) a.begin(), a.end()
#define size(container) (int)container.size()
#define int long long int
#define pb push_back
#define fh freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int mod = 1000000007;
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void read(vector<int> &a)
{
    for(auto &it : a)cin>>it;
}

inline void solve()
{
    // all the code goes here
    int n,w;cin>>n>>w;
    vector<int> a(n);
    read(a);
    int mx = LLONG_MIN,mi = LLONG_MAX;
    int sum = 0;
    f(i,0,n)
    {
        sum+=a[i];
        mx = max(mx,sum);
        mi = min(mi,sum);
    }
    mi = abs(min((int)0,mi));
    if(mi > w)
        cout<<0;
    else
        cout<<w-((mx>0?mx:0)+mi)+1;
    cout<<NL;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        fh;
    #endif
    startTime = clock();
    solve();
    fflush(stdin);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long L;
const char NL = '\n';
#define PI 3.14159265
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define testf int t;scanf("%d", &t);while (t--)
#define test int t;cin >> t;while (t--)
#define all(a) a.begin(), a.end()
#define size(container) (int)container.size()
#define int long long int
#define pb push_back
#define fh freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int mod = 1000000007;
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void read(vector<int> &a)
{
    for(auto &it : a)cin>>it;
}

inline void solve()
{
    // all the code goes here
    int n,w;cin>>n>>w;
    vector<int> a(n);
    read(a);
    int mx = LLONG_MIN,mi = LLONG_MAX;
    int sum = 0;
    f(i,0,n)
    {
        sum+=a[i];
        mx = max(mx,sum);
        mi = min(mi,sum);
    }
    mi = abs(min((int)0,mi));
    if(mi > w)
        cout<<0;
    else
        cout<<w-(mx>0?mx:0+mi)+1;
    cout<<NL;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        fh;
    #endif
    startTime = clock();
    solve();
    fflush(stdin);
    fflush(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long L;
const char NL = '\n';
#define PI 3.14159265
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define testf int t;scanf("%d", &t);while (t--)
#define test int t;cin >> t;while (t--)
#define all(a) a.begin(), a.end()
#define size(container) (int)container.size()
#define int long long int
#define pb push_back
#define fh freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int mod = 1000000007;
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void read(vector<int> &a)
{
    for(auto &it : a)cin>>it;
}

inline void solve()
{
    // all the code goes here
    int n,w;cin>>n>>w;
    vector<int> a(n);
    read(a);
    int mx = LLONG_MIN,mi = LLONG_MAX;
    int sum = 0;
    f(i,0,n)
    {
        sum+=a[i];
        mx = max(mx,sum);
        mi = min(mi,sum);
    }
    mi = abs(min((int)0,mi));
    mx = max(mi,mx);
    if(mi > w)
        cout<<0;
    else
        cout<<w-mx+1;
    cout<<NL;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        fh;
    #endif
    startTime = clock();
    solve();
    fflush(stdin);
    fflush(stdout);
    return 0;
}


/*
   author: rishi_mohan
   created_at: Thu 29 Oct 2020 09:06 PM
*/

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n, m;
    cin >> n >> m;

    long long ans = -1, sum = 0;
    int first = 0;
    for(int i=0; i<n; i++){
        long long x;
        cin >> x;
        if(i==0) first = x;
        sum += x;
        ans = max(sum, ans);
    }

    int res = 0;
    if(m >= ans){
        res = m-ans;
    }
    if(sum<0) res = 0;
    if(first>=0 && ans<=m) res+=1;
    if(n==1 && first==0) res+=1;
    cout << res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while(t--)
		solve();
}


/*
   author: rishi_mohan
   created_at: Thu 29 Oct 2020 09:06 PM
*/

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n, m;
    cin >> n >> m;

    long long ans = -1, sum = 0;
    int first = 0;
    for(int i=0; i<n; i++){
        long long x;
        cin >> x;
        if(i==0) first = x;
        sum += x;
        ans = max(sum, ans);
    }

    int res = 0;
    if(m >= ans){
        res = m-ans;
    }
    if(sum<0) res = 0;
    if(first>0 && ans<=m) res+=1;
    if(n==1 && first==0) res+=1;
    cout << res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while(t--)
		solve();
}


/*
   author: rishi_mohan
*/

#include<bits/stdc++.h>
using namespace std;

void solve(){
   int n, m;
   cin >> n >> m;

   int mini = 0, maxa = 0;
   int sum = 0;
   for(int i=0; i<n; i++){
       int x;
       cin >> x;
       sum += x;
       mini = min(mini, sum);
       maxa = max(maxa, sum);
   }
   cout << max(0, m-(maxa-mini)+1);// total - range + 1(for 0)
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while(t--)
		solve();
}


/*
   author: rishi_mohan
   created_at: Thu 29 Oct 2020 09:06 PM
*/

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n, m;
    cin >> n >> m;

    long long ans = -1, sum = 0;
    int first = 0;
    for(int i=0; i<n; i++){
        long long x;
        cin >> x;
        if(i==0) first = x;
        sum += x;
        ans = max(sum, ans);
    }

    int res = 0;
    if(m >= ans){
        res = m-ans;
    }
    if(sum<0) res = 0;
    if(sum>=0 && first>=0 && ans<=m) res+=1;
    if(n==1 && first==0) res+=1;
    cout << res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while(t--)
		solve();
}


/*
   author: rishi_mohan
   created_at: Thu 29 Oct 2020 09:06 PM
*/

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n, m;
    cin >> n >> m;

    long long ans = -1, sum = 0;

    for(int i=0; i<n; i++){
        long long x;
        cin >> x;
        sum += x;
        ans = max(sum, ans);
    }

    if(ans<0) ans = 0;
    else if(ans==0) ans = m;
    else ans = (m+1)-ans;

    if(n==1) ans = m+1;
    cout << ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while(t--)
		solve();
}


/*
   author: rishi_mohan
   created_at: Thu 29 Oct 2020 09:06 PM
*/

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n, m;
    cin >> n >> m;

    long long ans = -1, sum = 0;

    for(int i=0; i<n; i++){
        long long x;
        cin >> x;
        sum += x;
        ans = max(sum, ans);
    }

    int res = 0;
    if(m+1 > ans){
        if(ans==0) res = m;
        else res = (m+1)-ans;
    }
    if(sum<0) res = 0;
    cout << res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while(t--)
		solve();
}


/*
   author: rishi_mohan
   created_at: Thu 29 Oct 2020 09:06 PM
*/

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n, m;
    cin >> n >> m;

    long long ans = -1, sum = 0;

    for(int i=0; i<n; i++){
        long long x;
        cin >> x;
        sum += x;
        ans = max(sum, ans);
    }

    int res = 0;
    if(m+1 > ans){
        if(ans==0) res = m;
        else res = (m+1)-ans;
    }

    cout << res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while(t--)
		solve();
}


/*
   author: rishi_mohan
   created_at: Thu 29 Oct 2020 09:06 PM
*/

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n, m;
    cin >> n >> m;
    long long ans = -1, sum = 0;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        sum+=x;
        ans = max(sum, ans);
    }

    if(ans<0) ans = 0;
    else if(ans==0) ans = m;
    else ans = m+1-ans;

    cout << ans << '\n';
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while(t--)
		solve();
}


#include<iostream>
using namespace std;
int main()
{
	int n;long long total;cin >> n >> total;
	long long a[n];
	for(int i=0;i<n;i++) cin >> a[i];
	long long ans1=total;
	bool flag=1;
	for(int i=n-1;i>=0;i--)
	{
		if(flag)
			while(a[i]<0) i--;
		if(i<0)
			break;
		ans1-=a[i];
		flag=0;
		if(ans1>total)
		{
			cout << 0 << endl;return 0;
		}
	}
	long long ans2=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]<0)
			ans2+=a[i];
		else
			break;
	 }
	int ans=ans1-ans2;
	if(ans>=total)
		cout << total << endl;
	else
		cout << ans+1 << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ansn() printf("%d\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp(aa,bb) make_pair(aa,bb)
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
int main()
{
    int n,w;
    sdd(n,w);
    int cnt=0;
    int mx=0;
    int mn=0;
    r0(i,n)
    {
        int cur;
        sd(cur);
        cnt+=cur;
        mx=max(cnt,mx);
        mn=min(mn,cnt);
    }
    int ans=w-mx-abs(mn)+1;
    ans=max(ans,0);
    ansn();
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int m,n;cin >> m >> n;
	int mx = 0,mn = 0,cnt;
	for(int i=0;i<m;i++)
	{
		int t; cin >> t;
		cnt += t;
		mx = max(cnt,mx);
		mn = min(cnt,mn);
	}
	int ans = n-mx-fabs(mn)+1; ans = max(ans,0);
	cout << ans;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int m,n;cin >> m >> n;
	int mx = 0,mn = 0,cnt;
	for(int i=0;i<m;i++)
	{
		int t; cin >> t;
		cnt += t;
		mx = max(cnt,mx);
		mn = min(cnt,mn);
	}
	int ans = n-mx-fabs(mn)+1; ans = max(ans,0);
	cout << ans << endl;
}


#include<iostream>
using namespace std;
int main()
{
	int n;long long total;cin >> n >> total;
	long long a[n];
	for(int i=0;i<n;i++) cin >> a[i];
	long long ans=total;
	bool flag=1;
	for(int i=n-1;i>=0;i--)
	{
		if(flag)
			while(a[i]<0) i--;
		if(i<0)
			break;
		ans-=a[i];
		flag=0;
		if(ans>total)
		{
			cout << 0 << endl;return 0;
		}
	}
	if(ans>=total)
		cout << total << endl;
	else
		cout << ans+1 << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ansn() printf("%d\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp(aa,bb) make_pair(aa,bb)
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
int main()
{
    int n,w;
    sdd(n,w);
    int cnt=0;
    int mx=0;
    int mn=0;
    r0(i,n)
    {
        int cur;
        sd(cur);
        cnt+=cur;
        mx=max(cnt,mx);
        mn=min(mn,cnt);
    }
    int ans=w-mx-abs(mn)+1;
    ans=max(ans,0);
    ansn();
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int m,n;cin >> m >> n;
	int mx = 0,mn = 0,cnt;
	for(int i=0;i<m;i++)
	{
		int t; cin >> t;
		cnt += t;
		mx = max(cnt,mx);
		mn = min(cnt,mn);
	}
	int ans = n-mx-fabs(mn)+1; ans = max(ans,0);
	cout << ans;
	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int m,n;cin >> m >> n;
	int mx = 0,mn = 0,cnt;
	for(int i=0;i<m;i++)
	{
		int t; cin >> t;
		cnt += t;
		mx = max(cnt,mx);
		mn = min(cnt,mn);
	}
	int ans = n-mx-fabs(mn)+1; ans = max(ans,0);
	cout << ans << endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,i,j,thissum,maxsum,st,end,num[100001];
    thissum=0;maxsum=-99999;
    cin>>n;
    int a;
    cin >>a;
    for(i=1;i<=n;i++){
        cin>>num[i];
    }
    for(i=1;i<=n;i++){
        thissum=0;
        for(j=i;j<=n;j++){
        thissum+=num[j];
            if(thissum>maxsum){
                maxsum=thissum;
                st=i;end=j;
            }
            if(thissum<0){
                i=j;
                break;
            }
        }
    }
    if(a-maxsum+1>0)
    	cout<<a-maxsum+1<<endl;
    else
    	cout << 0 <<endl;
 }


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

ll n,w;
ll a[2000];
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    ll c = 0;
    ll cc = LLONG_MIN;
    ll s = 0LL;

    ff(i,1,n)
    {
        s += a[i];
        c = min(c, s);
        cc = max(cc, s);
    }
    if ( -c > w || cc > w)
    {
        cout << 0 << endl;
        return 0;
    }
    ll ans = w - (cc - c ) + 1LL;
    cout << max(ans,0LL);
}

/*

ll BIT[100100];

void update(int x, int delta)
{
    for(; x <= N; x += x&-x)
        BIT[x] += delta;
}

ll query(int x)
{
    ll sum = 0;
    for(; x > 0; x -= x&-x)
        sum += BIT[x];
    return sum;
}

bool prime[1000005];
void sieve()
{
    for(int i=4; i<=1000000; i+=2)
        prime[i]=false,prime[i-1]=true;
    prime[2]=true;
    for(int i=3; i<=1000; i+=2)
    {
        if(prime[i])
        {
            for(int j=i*i; j<=1000000; j+=i*2)
                prime[j]=false;
        }
    }
}

for (int i=0; i<n; i++)            Hi    ^_^  hack me if you can :P
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

*/
/*
freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);

ll pwmod(ll a, ll n, ll mod)
{
ll ret = 1;
while (n)
{
if (n & 1) ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}

int mx[]= {0,0,1,-1, 1,1,-1,-1};
int my[]= {1,-1,0,0, 1,-1,1,-1};

bool inside (int i,int j){return (i>=0 && i<n && j>=0 && j<m);}

void gcd(LL n,LL m,LL &d,LL &xx,LL &yy)
{
if(!m)
{
d=n;
xx=1;
yy=0;
}
else
{
gcd(m,n%m,d,yy,xx);
yy-=xx*(n/m);
}
}

int getm(int l,int r)
{
if(l>r)
return N;
if(l==r)
return 0;
if(l==r-1)
return s[l] != s[r];
if(s[l]==s[r])
return getm(l+1,r-1);
else
return 1+min(getm(l+1,r),getm(l,r-1));
}

int n, a[N];
int seg[N<<2];

void build(int nd,int L,int R)
{
if( L == R )
{
seg[nd]=a[L];
return ;
}
int mid = (L+R) >>1;
build(nd<<1,L, mid);
build(nd<<1|1,mid+1,R);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

void update(int nd,int L,int R,int idx,int val)
{
if( L == R )
{
seg[nd]=val;
return ;
}
int mid = (L+R) >>1;
if( idx<=mid )
update(nd<<1,  L,mid,idx,val);
else update(nd<<1|1,mid+1, R,idx,val);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

int query(int nd,int L,int R,int from,int to)
{
if( from<=L && R<=to )return seg[nd];
if( from>R || to<L )return -inf;

int mid = (L+R) >>1;

int ansl = query(nd<<1,  L,mid,from,to);
int ansr= query(nd<<1|1,mid+1, R,from,to);
return max( anrl,ansr );
}
*/


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

ll n,w;
ll a[2000];
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    ll c = 0;
    ll cc = LLONG_MIN;
    ll s = 0LL;

    ff(i,1,n)
    {
        s += a[i];
        c = min(c, s);
        cc = max(cc, s);
    }
    if ( -c > w || cc > w)
    {
        cout << 0 << endl;
        return 0;
    }
    ll ans = w - (cc - c ) + 1LL;
    cout << max(min(w+1LL,ans),0LL);
}

/*

ll BIT[100100];

void update(int x, int delta)
{
    for(; x <= N; x += x&-x)
        BIT[x] += delta;
}

ll query(int x)
{
    ll sum = 0;
    for(; x > 0; x -= x&-x)
        sum += BIT[x];
    return sum;
}

bool prime[1000005];
void sieve()
{
    for(int i=4; i<=1000000; i+=2)
        prime[i]=false,prime[i-1]=true;
    prime[2]=true;
    for(int i=3; i<=1000; i+=2)
    {
        if(prime[i])
        {
            for(int j=i*i; j<=1000000; j+=i*2)
                prime[j]=false;
        }
    }
}

for (int i=0; i<n; i++)            Hi    ^_^  hack me if you can :P
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

*/
/*
freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);

ll pwmod(ll a, ll n, ll mod)
{
ll ret = 1;
while (n)
{
if (n & 1) ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}

int mx[]= {0,0,1,-1, 1,1,-1,-1};
int my[]= {1,-1,0,0, 1,-1,1,-1};

bool inside (int i,int j){return (i>=0 && i<n && j>=0 && j<m);}

void gcd(LL n,LL m,LL &d,LL &xx,LL &yy)
{
if(!m)
{
d=n;
xx=1;
yy=0;
}
else
{
gcd(m,n%m,d,yy,xx);
yy-=xx*(n/m);
}
}

int getm(int l,int r)
{
if(l>r)
return N;
if(l==r)
return 0;
if(l==r-1)
return s[l] != s[r];
if(s[l]==s[r])
return getm(l+1,r-1);
else
return 1+min(getm(l+1,r),getm(l,r-1));
}

int n, a[N];
int seg[N<<2];

void build(int nd,int L,int R)
{
if( L == R )
{
seg[nd]=a[L];
return ;
}
int mid = (L+R) >>1;
build(nd<<1,L, mid);
build(nd<<1|1,mid+1,R);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

void update(int nd,int L,int R,int idx,int val)
{
if( L == R )
{
seg[nd]=val;
return ;
}
int mid = (L+R) >>1;
if( idx<=mid )
update(nd<<1,  L,mid,idx,val);
else update(nd<<1|1,mid+1, R,idx,val);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

int query(int nd,int L,int R,int from,int to)
{
if( from<=L && R<=to )return seg[nd];
if( from>R || to<L )return -inf;

int mid = (L+R) >>1;

int ansl = query(nd<<1,  L,mid,from,to);
int ansr= query(nd<<1|1,mid+1, R,from,to);
return max( anrl,ansr );
}
*/


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

ll n,w;
ll a[2000];
bool ok (ll m)
{
    ll s = m;
    ff(i,1,n)
    {
        s += a[i];
        if (s > w )
            return 0;
    }
    return 1;
}
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    ll c = LLONG_MAX;
    ll s = 0LL;

    ff(i,1,n)
    {
        s += a[i];
        c = min(c, s);
    }
    if ( -c > w)
    {
        cout << 0 << endl;
        return 0;
    }
    // cout << "c " << c << endl;
    ll l=max(0LL,-c);
    //cout << "l " << l << endl;
    ll h=w;
    ll m;
    while (l<h)
    {
        m = (l+h+1)/2;
        // cout << m << ' ' << ok(m) << endl;
        if (ok(m))
        {
            l = m;
        }
        else
        {
            h = m-1;
        }
    }
    ll ans = l+1;
    if ( c < 0LL)
        ans += c;
    cout << max(min(w+1LL,ans),0LL);
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

ll n,w;
ll a[2000];
bool ok (int m)
{
    ll s = m;
    ff(i,1,n)
    {
        s += a[i];
        if (s > w )
            return 0;
    }
    return 1;
}
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    ll c = LLONG_MAX;
    ll s = 0;

    ff(i,1,n)
    {
        s += a[i];
        c = min(c, s);
    }
    if ( -c > w)
    {
        cout << 0 << endl;
        return 0;
    }
    // cout << "c " << c << endl;
    ll l=max(0LL,-c);
    //cout << "l " << l << endl;
    ll h=w;
    ll m;
    while (l<h)
    {
        m = (l+h+1)/2;
        // cout << m << ' ' << ok(m) << endl;
        if (ok(m))
        {
            l = m;
        }
        else
        {
            h = m-1;
        }
    }
    ll ans = l+1;
    if ( c < 0LL)
        ans += c;
    cout << ans;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

ll n,w;
ll a[2000];
bool ok (ll m)
{
    ll s = m;
    ff(i,1,n)
    {
        s += a[i];
        if (s > w )
            return 0;
    }
    return 1;
}
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    ll c = LLONG_MAX;
    ll s = 0LL;

    ff(i,1,n)
    {
        s += a[i];
        c = min(c, s);
    }
    if ( -c > w)
    {
        cout << 0 << endl;
        return 0;
    }
    // cout << "c " << c << endl;
    ll l=max(0LL,-c);
    //cout << "l " << l << endl;
    ll h=w;
    ll m;
    while (l<h)
    {
        m = (l+h+1)/2;
        // cout << m << ' ' << ok(m) << endl;
        if (ok(m))
        {
            l = m;
        }
        else
        {
            h = m-1;
        }
    }
    ll ans = l+1;
    if ( c < 0LL)
        ans += c;
    cout << max(min(w+1LL,ans),1LL);
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

ll n,w;
ll a[2000];
bool ok (ll m)
{
    ll s = m;
    ff(i,1,n)
    {
        s += a[i];
        if (s > w )
            return 0;
    }
    return 1;
}
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    ll c = LLONG_MAX;
    ll s = 0LL;

    ff(i,1,n)
    {
        s += a[i];
        c = min(c, s);
    }
    if ( -c > w)
    {
        cout << 0 << endl;
        return 0;
    }
    // cout << "c " << c << endl;
    ll l=max(0LL,-c);
    //cout << "l " << l << endl;
    ll h=w;
    ll m;
    while (l<h)
    {
        m = (l+h+1LL)/2LL;
        // cout << m << ' ' << ok(m) << endl;
        if (ok(m))
        {
            l = m;
        }
        else
        {
            h = m-1LL;
        }
    }
    ll ans = l+1LL;
    if ( c < 0LL)
        ans += c;
    cout << max(min(w+1LL,ans),0LL);
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

ll n,w;
ll a[2000];
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    ll c = 0;
    ll cc = 0;
    ll s = 0LL;

    ff(i,1,n)
    {
        s += a[i];
        if ( s < 0 LL)
        c = min(c, -s);
        cc = max(cc, s);
    }
    ll ans = w - (cc + c ) + 1LL;
    cout << max(ans,0LL);
}

/*

ll BIT[100100];

void update(int x, int delta)
{
    for(; x <= N; x += x&-x)
        BIT[x] += delta;
}

ll query(int x)
{
    ll sum = 0;
    for(; x > 0; x -= x&-x)
        sum += BIT[x];
    return sum;
}

bool prime[1000005];
void sieve()
{
    for(int i=4; i<=1000000; i+=2)
        prime[i]=false,prime[i-1]=true;
    prime[2]=true;
    for(int i=3; i<=1000; i+=2)
    {
        if(prime[i])
        {
            for(int j=i*i; j<=1000000; j+=i*2)
                prime[j]=false;
        }
    }
}

for (int i=0; i<n; i++)            Hi    ^_^  hack me if you can :P
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

*/
/*
freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);

ll pwmod(ll a, ll n, ll mod)
{
ll ret = 1;
while (n)
{
if (n & 1) ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}

int mx[]= {0,0,1,-1, 1,1,-1,-1};
int my[]= {1,-1,0,0, 1,-1,1,-1};

bool inside (int i,int j){return (i>=0 && i<n && j>=0 && j<m);}

void gcd(LL n,LL m,LL &d,LL &xx,LL &yy)
{
if(!m)
{
d=n;
xx=1;
yy=0;
}
else
{
gcd(m,n%m,d,yy,xx);
yy-=xx*(n/m);
}
}

int getm(int l,int r)
{
if(l>r)
return N;
if(l==r)
return 0;
if(l==r-1)
return s[l] != s[r];
if(s[l]==s[r])
return getm(l+1,r-1);
else
return 1+min(getm(l+1,r),getm(l,r-1));
}

int n, a[N];
int seg[N<<2];

void build(int nd,int L,int R)
{
if( L == R )
{
seg[nd]=a[L];
return ;
}
int mid = (L+R) >>1;
build(nd<<1,L, mid);
build(nd<<1|1,mid+1,R);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

void update(int nd,int L,int R,int idx,int val)
{
if( L == R )
{
seg[nd]=val;
return ;
}
int mid = (L+R) >>1;
if( idx<=mid )
update(nd<<1,  L,mid,idx,val);
else update(nd<<1|1,mid+1, R,idx,val);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

int query(int nd,int L,int R,int from,int to)
{
if( from<=L && R<=to )return seg[nd];
if( from>R || to<L )return -inf;

int mid = (L+R) >>1;

int ansl = query(nd<<1,  L,mid,from,to);
int ansr= query(nd<<1|1,mid+1, R,from,to);
return max( anrl,ansr );
}
*/


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

ll n,w;
ll a[2000];
bool ok (ll m)
{
    ll s = m;
    ff(i,1,n)
    {
        s += a[i];
        if (s > w )
            return 0;
    }
    return 1;
}
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    ll c = LLONG_MAX;
    ll s = 0LL;

    ff(i,1,n)
    {
        s += a[i];
        c = min(c, s);
    }
    if ( -c > w)
    {
        cout << 0 << endl;
        return 0;
    }
    // cout << "c " << c << endl;
    ll l=max(0LL,-c);
    //cout << "l " << l << endl;
    ll h=w;
    ll m;
    while (l<h)
    {
        m = (l+h+1LL)/2LL;
        // cout << m << ' ' << ok(m) << endl;
        if (ok(m))
        {
            l = m;
        }
        else
        {
            h = m-1LL;
        }
    }
    ll ans = l+1LL;
    if ( c < 0LL)
        ans += c;
    cout << max(min(w+1LL,ans),0LL);
}

/*

ll BIT[100100];

void update(int x, int delta)
{
    for(; x <= N; x += x&-x)
        BIT[x] += delta;
}

ll query(int x)
{
    ll sum = 0;
    for(; x > 0; x -= x&-x)
        sum += BIT[x];
    return sum;
}

bool prime[1000005];
void sieve()
{
    for(int i=4; i<=1000000; i+=2)
        prime[i]=false,prime[i-1]=true;
    prime[2]=true;
    for(int i=3; i<=1000; i+=2)
    {
        if(prime[i])
        {
            for(int j=i*i; j<=1000000; j+=i*2)
                prime[j]=false;
        }
    }
}

for (int i=0; i<n; i++)            Hi    ^_^  hack me if you can :P
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

*/
/*
freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);

ll pwmod(ll a, ll n, ll mod)
{
ll ret = 1;
while (n)
{
if (n & 1) ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}

int mx[]= {0,0,1,-1, 1,1,-1,-1};
int my[]= {1,-1,0,0, 1,-1,1,-1};

bool inside (int i,int j){return (i>=0 && i<n && j>=0 && j<m);}

void gcd(LL n,LL m,LL &d,LL &xx,LL &yy)
{
if(!m)
{
d=n;
xx=1;
yy=0;
}
else
{
gcd(m,n%m,d,yy,xx);
yy-=xx*(n/m);
}
}

int getm(int l,int r)
{
if(l>r)
return N;
if(l==r)
return 0;
if(l==r-1)
return s[l] != s[r];
if(s[l]==s[r])
return getm(l+1,r-1);
else
return 1+min(getm(l+1,r),getm(l,r-1));
}

int n, a[N];
int seg[N<<2];

void build(int nd,int L,int R)
{
if( L == R )
{
seg[nd]=a[L];
return ;
}
int mid = (L+R) >>1;
build(nd<<1,L, mid);
build(nd<<1|1,mid+1,R);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

void update(int nd,int L,int R,int idx,int val)
{
if( L == R )
{
seg[nd]=val;
return ;
}
int mid = (L+R) >>1;
if( idx<=mid )
update(nd<<1,  L,mid,idx,val);
else update(nd<<1|1,mid+1, R,idx,val);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

int query(int nd,int L,int R,int from,int to)
{
if( from<=L && R<=to )return seg[nd];
if( from>R || to<L )return -inf;

int mid = (L+R) >>1;

int ansl = query(nd<<1,  L,mid,from,to);
int ansr= query(nd<<1|1,mid+1, R,from,to);
return max( anrl,ansr );
}
*/


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

ll n,w;
ll a[2000];
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    ll c = 0;
    ll cc = 0;
    ll s = 0LL;

    ff(i,1,n)
    {
        s += a[i];
        if ( s < 0LL)
        c = max(c, -s);
        cc = max(cc, s);
    }
    ll ans = w - (cc + c ) + 1LL;
    cout << max(ans,0LL);
}

/*

ll BIT[100100];

void update(int x, int delta)
{
    for(; x <= N; x += x&-x)
        BIT[x] += delta;
}

ll query(int x)
{
    ll sum = 0;
    for(; x > 0; x -= x&-x)
        sum += BIT[x];
    return sum;
}

bool prime[1000005];
void sieve()
{
    for(int i=4; i<=1000000; i+=2)
        prime[i]=false,prime[i-1]=true;
    prime[2]=true;
    for(int i=3; i<=1000; i+=2)
    {
        if(prime[i])
        {
            for(int j=i*i; j<=1000000; j+=i*2)
                prime[j]=false;
        }
    }
}

for (int i=0; i<n; i++)            Hi    ^_^  hack me if you can :P
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

*/
/*
freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);

ll pwmod(ll a, ll n, ll mod)
{
ll ret = 1;
while (n)
{
if (n & 1) ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}

int mx[]= {0,0,1,-1, 1,1,-1,-1};
int my[]= {1,-1,0,0, 1,-1,1,-1};

bool inside (int i,int j){return (i>=0 && i<n && j>=0 && j<m);}

void gcd(LL n,LL m,LL &d,LL &xx,LL &yy)
{
if(!m)
{
d=n;
xx=1;
yy=0;
}
else
{
gcd(m,n%m,d,yy,xx);
yy-=xx*(n/m);
}
}

int getm(int l,int r)
{
if(l>r)
return N;
if(l==r)
return 0;
if(l==r-1)
return s[l] != s[r];
if(s[l]==s[r])
return getm(l+1,r-1);
else
return 1+min(getm(l+1,r),getm(l,r-1));
}

int n, a[N];
int seg[N<<2];

void build(int nd,int L,int R)
{
if( L == R )
{
seg[nd]=a[L];
return ;
}
int mid = (L+R) >>1;
build(nd<<1,L, mid);
build(nd<<1|1,mid+1,R);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

void update(int nd,int L,int R,int idx,int val)
{
if( L == R )
{
seg[nd]=val;
return ;
}
int mid = (L+R) >>1;
if( idx<=mid )
update(nd<<1,  L,mid,idx,val);
else update(nd<<1|1,mid+1, R,idx,val);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

int query(int nd,int L,int R,int from,int to)
{
if( from<=L && R<=to )return seg[nd];
if( from>R || to<L )return -inf;

int mid = (L+R) >>1;

int ansl = query(nd<<1,  L,mid,from,to);
int ansr= query(nd<<1|1,mid+1, R,from,to);
return max( anrl,ansr );
}
*/


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

ll n,w;
ll a[2000];
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    ll c = 0;
    ll cc = 0;
    ll s = 0LL;

    ff(i,1,n)
    {
        s += a[i];
        c = min(c, s);
        cc = max(cc, s);
    }
    c = max(c,0LL);
    ll ans = w - (cc + c ) + 1LL;
    cout << max(ans,0LL);
}

/*

ll BIT[100100];

void update(int x, int delta)
{
    for(; x <= N; x += x&-x)
        BIT[x] += delta;
}

ll query(int x)
{
    ll sum = 0;
    for(; x > 0; x -= x&-x)
        sum += BIT[x];
    return sum;
}

bool prime[1000005];
void sieve()
{
    for(int i=4; i<=1000000; i+=2)
        prime[i]=false,prime[i-1]=true;
    prime[2]=true;
    for(int i=3; i<=1000; i+=2)
    {
        if(prime[i])
        {
            for(int j=i*i; j<=1000000; j+=i*2)
                prime[j]=false;
        }
    }
}

for (int i=0; i<n; i++)            Hi    ^_^  hack me if you can :P
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

*/
/*
freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);

ll pwmod(ll a, ll n, ll mod)
{
ll ret = 1;
while (n)
{
if (n & 1) ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}

int mx[]= {0,0,1,-1, 1,1,-1,-1};
int my[]= {1,-1,0,0, 1,-1,1,-1};

bool inside (int i,int j){return (i>=0 && i<n && j>=0 && j<m);}

void gcd(LL n,LL m,LL &d,LL &xx,LL &yy)
{
if(!m)
{
d=n;
xx=1;
yy=0;
}
else
{
gcd(m,n%m,d,yy,xx);
yy-=xx*(n/m);
}
}

int getm(int l,int r)
{
if(l>r)
return N;
if(l==r)
return 0;
if(l==r-1)
return s[l] != s[r];
if(s[l]==s[r])
return getm(l+1,r-1);
else
return 1+min(getm(l+1,r),getm(l,r-1));
}

int n, a[N];
int seg[N<<2];

void build(int nd,int L,int R)
{
if( L == R )
{
seg[nd]=a[L];
return ;
}
int mid = (L+R) >>1;
build(nd<<1,L, mid);
build(nd<<1|1,mid+1,R);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

void update(int nd,int L,int R,int idx,int val)
{
if( L == R )
{
seg[nd]=val;
return ;
}
int mid = (L+R) >>1;
if( idx<=mid )
update(nd<<1,  L,mid,idx,val);
else update(nd<<1|1,mid+1, R,idx,val);
seg[nd]=max( seg[nd<<1], seg[nd<<1|1] );
}

int query(int nd,int L,int R,int from,int to)
{
if( from<=L && R<=to )return seg[nd];
if( from>R || to<L )return -inf;

int mid = (L+R) >>1;

int ansl = query(nd<<1,  L,mid,from,to);
int ansr= query(nd<<1|1,mid+1, R,from,to);
return max( anrl,ansr );
}
*/


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

int n,w;
int a[2000];
bool ok (int m)
{
    int s = m;
    ff(i,1,n)
    {
        s += a[i];
        if (s > w )
            return 0;
    }
    return 1;
}
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    int c = INT_MAX;
    int s = 0;

    ff(i,1,n)
    {
        s += a[i];
        c = min(c, s);
    }
    if ( -c > w)
    {
        cout << 0 << endl;
        return 0;
    }
    // cout << "c " << c << endl;
    int l=max(0,-c);
    //cout << "l " << l << endl;
    int h=w;
    int m;
    while (l<h)
    {
        m = (l+h+1)/2;
        // cout << m << ' ' << ok(m) << endl;
        if (ok(m))
        {
            l = m;
        }
        else
        {
            h = m-1;
        }
    }
    int ans = l+1;
    if ( c < 0)
        ans += c;
    cout << ans;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<ll,int> pli;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define f          first
//#define s          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
const int N = 100100;
const int maxn = 105;
//////////////////////  Hi ^_^  hack me if you can :P

ll n,w;
ll a[2000];
bool ok (ll m)
{
    ll s = m;
    ff(i,1,n)
    {
        s += a[i];
        if (s > w )
            return 0;
    }
    return 1;
}
int main()
{
    speed;
    cin >> n >> w;
    ff(i,1,n)
    {
        cin >> a[i];
    }
    ll c = LLONG_MAX;
    ll cc = LLONG_MIN;
    ll s = 0LL;

    ff(i,1,n)
    {
        s += a[i];
        c = min(c, s);
        cc = max(cc, s);
    }
    if ( -c > w || cc > w)
    {
        cout << 0 << endl;
        return 0;
    }
    // cout << "c " << c << endl;
    ll l=max(0LL,-c);
    //cout << "l " << l << endl;
    ll h=w;
    ll m;
    while (l<h)
    {
        m = (l+h+1LL)/2LL;
        // cout << m << ' ' << ok(m) << endl;
        if (ok(m))
        {
            l = m;
        }
        else
        {
            h = m-1LL;
        }
    }
    ll ans = (h>0?l:-1LL) + 1LL;
    if ( c < 0LL)
        ans += c;
    cout << max(min(w+1LL,ans),0LL);
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 1000000 + 5 /* 1e6 +  5 */

#define IOS ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define endl '\n'

#define PQ priority_queue

#define forn(x, y, z) for (int x = y; x < z; ++x)

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define init(x, y) memset((x), (y), sizeof(x))

#define pii pair<int, int>
#define piii pair<int, pii>

#define pb push_back
#define eb emplace_back

#define fs first
#define sc second

using namespace std;

typedef long long lint;

/*
bool chk[N];

vector<lint> get_prime(lint max_n) {
	vector<lint> ret;
	for (lint i = 2; i * i <= max_n; ++i) if (chk[i] == false) {
		ret.emplace_back(i);
		for (lint j = i + i; j <= max_n; ++j) {
			chk[j] = true;
		}
	}
	return ret;
}
*/

lint gcd(lint a, lint b) {
	a = abs(a), b = abs(b);
	if (a < b) swap(a, b);
	return b ? gcd(b, a % b) : a;
}

lint lcm(lint a, lint b) { return a * b / gcd(a, b); }

lint fast_pow(lint x, lint exp, lint mod) {
	lint ret = 1;
	while (exp) {
		if (exp & 1) ret = (ret * x) % mod;
		x = (x * x) % mod;
		exp >>= 1;
	}
	return ret;
}

const int dx[] = { 0, 0, -1, 1 };
const int dy[] = { -1, 1, 0, 0 };

const int inf = (int)1e9 + 5;

vector<vector<int> > adj;
vector<int> v;

PQ<int> q;
map<int, int> mp;
set<int> st;

int n, w, a[N];

int32_t main(void)
{
	IOS;

	cin >> n >> w;

	int max_v = -inf, min_v = 0;

	forn(i, 1, n + 1) {
		cin >> a[i];
		a[i] += a[i - 1];
		max_v = max(max_v, a[i]);
		min_v = min(min_v, a[i]);
	}

	int s = -min_v, e = w - max_v;

	int res = e - s + 1;
	if (s > e) res = -1;

	cout << res;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 1000000 + 5 /* 1e6 +  5 */

#define IOS ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define endl '\n'

#define PQ priority_queue

#define forn(x, y, z) for (int x = y; x < z; ++x)

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define init(x, y) memset((x), (y), sizeof(x))

#define pii pair<int, int>
#define piii pair<int, pii>

#define pb push_back
#define eb emplace_back

#define fs first
#define sc second

using namespace std;

typedef long long lint;

/*
bool chk[N];

vector<lint> get_prime(lint max_n) {
	vector<lint> ret;
	for (lint i = 2; i * i <= max_n; ++i) if (chk[i] == false) {
		ret.emplace_back(i);
		for (lint j = i + i; j <= max_n; ++j) {
			chk[j] = true;
		}
	}
	return ret;
}
*/

lint gcd(lint a, lint b) {
	a = abs(a), b = abs(b);
	if (a < b) swap(a, b);
	return b ? gcd(b, a % b) : a;
}

lint lcm(lint a, lint b) { return a * b / gcd(a, b); }

lint fast_pow(lint x, lint exp, lint mod) {
	lint ret = 1;
	while (exp) {
		if (exp & 1) ret = (ret * x) % mod;
		x = (x * x) % mod;
		exp >>= 1;
	}
	return ret;
}

const int dx[] = { 0, 0, -1, 1 };
const int dy[] = { -1, 1, 0, 0 };

const int inf = (int)1e9 + 5;

vector<vector<int> > adj;
vector<int> v;

PQ<int> q;
map<int, int> mp;
set<int> st;

lint n, w, a[N];

int32_t main(void)
{
	IOS;

	cin >> n >> w;

	lint max_v = 0, min_v = 0;

	forn(i, 1, n + 1) {
		cin >> a[i];
		a[i] += a[i - 1];
		max_v = max(max_v, a[i]);
		min_v = min(min_v, a[i]);
	}

	lint s = -min_v, e = w - max_v;

	lint res = e - s + 1;
	if (s > e) res = -1;

	cout << res;

	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 300000 + 5 /* 3e5 +  5 */

#define pii pair<int, int>

#define piii pair<int, pair<int, int> >

using namespace std;

typedef long long ll;

int dx[] = { 0, 0, 0, -1, -1, -1, 1, 1, 1 };
int dy[] = { 0, 1, -1, 0, 1, -1, 0, 1, -1 };

ll n, w, ary[N], sum[N];

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> w;

	ll min_w = 0, max_w = 0;

	for (int i = 1; i <= n; ++i) {
		cin >> ary[i];
		sum[i] = sum[i - 1] + ary[i];
		max_w = max(max_w, sum[i]);
		min_w = min(min_w, sum[i]);
	}

	if (max_w > w || min_w < -w) cout << 0;

	ll s = w - max_w, e = 0;
	if (min_w < 0) e = llabs(min_w);

	cout << llabs(e - s) + 1;

	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 300000 + 5 /* 3e5 +  5 */

#define pii pair<int, int>

#define piii pair<int, pair<int, int> >

using namespace std;

typedef long long ll;

int dx[] = { 0, 0, 0, -1, -1, -1, 1, 1, 1 };
int dy[] = { 0, 1, -1, 0, 1, -1, 0, 1, -1 };

ll n, w, ary[N], sum[N];

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> w;

	ll min_w = (ll)1e18, max_w = (ll)-1e18;

	for (int i = 1; i <= n; ++i) {
		cin >> ary[i];
		sum[i] = sum[i - 1] + ary[i];
		max_w = max(max_w, sum[i]);
		min_w = min(min_w, sum[i]);
	}

	ll s = w - max_w, e = -min_w;

	if (e > s) {
		cout << 0;
		return 0;
	}

	cout << s - e + 1;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 1000000 + 5 /* 1e6 +  5 */

#define IOS ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define endl '\n'

#define PQ priority_queue

#define forn(x, y, z) for (int x = y; x < z; ++x)

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define init(x, y) memset((x), (y), sizeof(x))

#define pii pair<int, int>
#define piii pair<int, pii>

#define pb push_back
#define eb emplace_back

#define fs first
#define sc second

using namespace std;

typedef long long lint;

/*
bool chk[N];

vector<lint> get_prime(lint max_n) {
	vector<lint> ret;
	for (lint i = 2; i * i <= max_n; ++i) if (chk[i] == false) {
		ret.emplace_back(i);
		for (lint j = i + i; j <= max_n; ++j) {
			chk[j] = true;
		}
	}
	return ret;
}
*/

lint gcd(lint a, lint b) {
	a = abs(a), b = abs(b);
	if (a < b) swap(a, b);
	return b ? gcd(b, a % b) : a;
}

lint lcm(lint a, lint b) { return a * b / gcd(a, b); }

lint fast_pow(lint x, lint exp, lint mod) {
	lint ret = 1;
	while (exp) {
		if (exp & 1) ret = (ret * x) % mod;
		x = (x * x) % mod;
		exp >>= 1;
	}
	return ret;
}

const int dx[] = { 0, 0, -1, 1 };
const int dy[] = { -1, 1, 0, 0 };

const int inf = (int)1e9 + 5;

vector<vector<int> > adj;
vector<int> v;

PQ<int> q;
map<int, int> mp;
set<int> st;

lint n, w, a[N];

int32_t main(void)
{
	IOS;

	cin >> n >> w;

	lint max_v = 0, min_v = 0;

	forn(i, 1, n + 1) {
		cin >> a[i];
		a[i] += a[i - 1];
		max_v = max(max_v, a[i]);
		min_v = min(min_v, a[i]);
	}

	lint s = -min_v, e = w - max_v;

	if (s > e || e < 0)
		cout << -1;
	else
		cout << e - s + 1;

	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 300000 + 5 /* 3e5 +  5 */

#define pii pair<int, int>

#define piii pair<int, pair<int, int> >

using namespace std;

typedef long long ll;

int dx[] = { 0, 0, 0, -1, -1, -1, 1, 1, 1 };
int dy[] = { 0, 1, -1, 0, 1, -1, 0, 1, -1 };

ll n, w, ary[N], sum[N];

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> w;

	ll min_w = 0, max_w = 0;

	for (int i = 1; i <= n; ++i) {
		cin >> ary[i];
		sum[i] = sum[i - 1] + ary[i];
		max_w = max(max_w, sum[i]);
		min_w = min(min_w, sum[i]);
	}

	ll s = w - max_w, e = -min_w;

	if (e + max_w > w) {
		cout << 0;
		return 0;
	}

	cout << s - e + 1;

	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 300000 + 5 /* 3e5 +  5 */

#define pii pair<int, int>

#define piii pair<int, pair<int, int> >

using namespace std;

typedef long long ll;

int dx[] = { 0, 0, 0, -1, -1, -1, 1, 1, 1 };
int dy[] = { 0, 1, -1, 0, 1, -1, 0, 1, -1 };

ll n, w, ary[N], sum[N];

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> w;

	ll min_w = (ll)1e18, max_w = (ll)-1e18;

	for (int i = 1; i <= n; ++i) {
		cin >> ary[i];
		sum[i] = sum[i - 1] + ary[i];
		max_w = max(max_w, sum[i]);
		min_w = min(min_w, sum[i]);
	}

	ll s = -min_w, e = w - max_w;

	if (s > e) {
		cout << 0;
		return 0;
	}

	cout << e - s + 1;

	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 300000 + 5 /* 3e5 +  5 */

#define pii pair<int, int>

#define piii pair<int, pair<int, int> >

using namespace std;

typedef long long ll;

int dx[] = { 0, 0, 0, -1, -1, -1, 1, 1, 1 };
int dy[] = { 0, 1, -1, 0, 1, -1, 0, 1, -1 };

ll n, w, ary[N], sum[N];

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> w;

	ll min_w = (ll)1e18, max_w = (ll)-1e18;

	for (int i = 1; i <= n; ++i) {
		cin >> ary[i];
		sum[i] = sum[i - 1] + ary[i];
		max_w = max(max_w, sum[i]);
		min_w = min(min_w, sum[i]);
	}

	if (max_w > w || min_w < -w) cout << 0;

	ll s = w - max_w, e = 0;
	if (min_w < 0) e = llabs(min_w);

	cout << llabs(e - s) + 1;

	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 300000 + 5 /* 3e5 +  5 */

#define pii pair<int, int>

#define piii pair<int, pair<int, int> >

using namespace std;

typedef long long ll;

int dx[] = { 0, 0, 0, -1, -1, -1, 1, 1, 1 };
int dy[] = { 0, 1, -1, 0, 1, -1, 0, 1, -1 };

ll n, w, ary[N], sum[N];

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> w;

	ll min_w = 0, max_w = 0;

	for (int i = 1; i <= n; ++i) {
		cin >> ary[i];
		sum[i] = sum[i - 1] + ary[i];
		max_w = max(max_w, sum[i]);
		min_w = min(min_w, sum[i]);
	}

	ll s = -min_w, e = w - max_w;

	if (s > e) {
		cout << 0;
		return 0;
	}

	cout << e - s + 1;

	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 300000 + 5 /* 3e5 +  5 */

#define pii pair<int, int>

#define piii pair<int, pair<int, int> >

using namespace std;

typedef long long ll;

int dx[] = { 0, 0, 0, -1, -1, -1, 1, 1, 1 };
int dy[] = { 0, 1, -1, 0, 1, -1, 0, 1, -1 };

ll n, w, ary[N], sum[N];

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> w;

	ll min_w = (ll)1e18, max_w = (ll)-1e18;

	for (int i = 1; i <= n; ++i) {
		cin >> ary[i];
		sum[i] = sum[i - 1] + ary[i];
		max_w = max(max_w, sum[i]);
		min_w = min(min_w, sum[i]);
	}

	if (max_w > w || min_w < -w) {
		cout << 0;
		return 0;
	}

	ll s = w - max_w, e = 0;
	if (min_w < 0) e = llabs(min_w);

	cout << llabs(e - s) + 1;

	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 300000 + 5 /* 3e5 +  5 */

#define pii pair<int, int>

#define piii pair<int, pair<int, int> >

using namespace std;

typedef long long ll;

int dx[] = { 0, 0, -1, 1 };
int dy[] = { -1, 1, 0, 0 };

ll n, w, ary[N], sum[N];

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> w;

	ll max_v = 0, min_v = 0;

	for (int i = 1; i <= n; ++i) {
		cin >> ary[i];
		sum[i] = sum[i - 1] + ary[i];
		max_v = max(max_v, sum[i]);
		min_v = min(min_v, sum[i]);
	}

	ll s = -min_v, e = w - max_v;

	if (s + max_v > w) {
		cout << 0;
		return 0;
	}

	cout << e - s + 1;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <algorithm>
#include <functional>

#define N 1000000 + 5 /* 1e6 +  5 */

#define IOS ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define endl '\n'

#define PQ priority_queue

#define forn(x, y, z) for (int x = y; x < z; ++x)

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define init(x, y) memset((x), (y), sizeof(x))

#define pii pair<int, int>
#define piii pair<int, pii>

#define pb push_back
#define eb emplace_back

#define fs first
#define sc second

using namespace std;

typedef long long lint;

/*
bool chk[N];

vector<lint> get_prime(lint max_n) {
	vector<lint> ret;
	for (lint i = 2; i * i <= max_n; ++i) if (chk[i] == false) {
		ret.emplace_back(i);
		for (lint j = i + i; j <= max_n; ++j) {
			chk[j] = true;
		}
	}
	return ret;
}
*/

lint gcd(lint a, lint b) {
	a = abs(a), b = abs(b);
	if (a < b) swap(a, b);
	return b ? gcd(b, a % b) : a;
}

lint lcm(lint a, lint b) { return a * b / gcd(a, b); }

lint fast_pow(lint x, lint exp, lint mod) {
	lint ret = 1;
	while (exp) {
		if (exp & 1) ret = (ret * x) % mod;
		x = (x * x) % mod;
		exp >>= 1;
	}
	return ret;
}

const int dx[] = { 0, 0, -1, 1 };
const int dy[] = { -1, 1, 0, 0 };

const int inf = (int)1e9 + 5;

vector<vector<int> > adj;
vector<int> v;

PQ<int> q;
map<int, int> mp;
set<int> st;

lint n, w, a[N];

int32_t main(void)
{
	IOS;

	cin >> n >> w;

	lint max_v = 0, min_v = 0;

	forn(i, 1, n + 1) {
		cin >> a[i];
		a[i] += a[i - 1];
		max_v = max(max_v, a[i]);
		min_v = min(min_v, a[i]);
	}

	lint s = -min_v, e = w - max_v;

	if (s > e)
		cout << 0;
	else
		cout << e - s + 1;

	return 0;
}


#include<iostream>
using namespace std;
int main(){
    long long int n,w,maxs=INT_MIN,mins=INT_MAX;long long int a[n+1];cin>>n>>w;
    for(long long int i=1;i<=n;i++){cin>>a[i];a[i]+=a[i-1];if(a[i]>maxs)maxs=a[i];if(a[i]<mins)mins=a[i];}
    long long int ans=max(-1,w-maxs);
    if(mins<0)
        ans-=mins;
    cout<<ans+1;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    long long int n,w,maxs=INT_MIN,mins=INT_MAX;long long int a[n+1];cin>>n>>w;a[0]=0;
    for(long long int i=1;i<=n;i++){cin>>a[i];a[i]+=a[i-1];if(a[i]>maxs)maxs=a[i];if(a[i]<mins)mins=a[i];}
    if(w<maxs || -1*mins>w){cout<<0;return 0;}
    long long int ans=(w-maxs<0)?-1:w-maxs;
    if(mins<0)
        ans+=mins;
    cout<<ans+1;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    long long int n,w,maxs=INT_MIN,mins=INT_MAX;cin>>n>>w;long long int a[n+1];a[0]=0;
    for(long long int i=1;i<=n;i++){cin>>a[i];a[i]+=a[i-1];if(a[i]>maxs)maxs=a[i];if(a[i]<mins)mins=a[i];}
    long long int ans=w-maxs;
    if(mins<0)
        ans+=mins;
    ans++;
    if(ans<0 || ans>w)cout<<0;
    else cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    long long int n,w,maxs=INT_MIN,mins=INT_MAX;long long int a[n+1];cin>>n>>w;
    for(long long int i=1;i<=n;i++){cin>>a[i];a[i]+=a[i-1];if(a[i]>maxs)maxs=a[i];if(a[i]<mins)mins=a[i];}
    if(w<maxs || -1*mins>w){cout<<0;return 0;}
    long long int ans=(w-maxs<0)?-1:w-maxs;
    if(mins<0)
        ans+=mins;
    cout<<ans+1;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    long long int n,w,maxs=INT_MIN,mins=INT_MAX;long long int a[n+1];cin>>n>>w;a[0]=0;
    for(long long int i=1;i<=n;i++){cin>>a[i];a[i]+=a[i-1];if(a[i]>maxs)maxs=a[i];if(a[i]<mins)mins=a[i];}
    if(w<maxs || -1*mins>w){cout<<0;return 0;}
    long long int ans=w-maxs+mins+1;
    if(ans<0 || ans>w)cout<<0;
    else cout<<ans+1;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    long long int n,w,maxs=INT_MIN,mins=INT_MAX;long long int a[n+1];cin>>n>>w;a[0]=0;
    for(long long int i=1;i<=n;i++){cin>>a[i];a[i]+=a[i-1];if(a[i]>maxs)maxs=a[i];if(a[i]<mins)mins=a[i];}
    long long int ans=w-maxs;
    if(mins<0)
        ans+=mins;
    ans++;
    if(ans<0 || ans>w)cout<<0;
    else cout<<ans;
    return 0;
}