#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//template<typename T>
#define o_set(T) tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//use it like o_set(ll) x;  --> x.order.....
//-->for pair<ll,ll> : second element as index and for search use INT_MAX...
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

#define fast ios::sync_with_stdio(false);cin.tie(0);cout<<setprecision(25)
#define pb push_back
#define I insert
#define F first
#define S second
#define digit(x) floor(log10(x))+1
const long long M1=1000000007;
const long long  M2=998244353;
#define L_MAX 1e18
using ll = long long;
using ld = long double;
using ii = pair<ll,ll>;
using matrix = vector<vector<ll>>;
using arr = vector<ll>;
using vs = vector<string>;
using pv = vector<ii>;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
template<typename T>
void showArr(T a){
    for(auto i : a) cout<<i<<" ";
    cout<<endl;
}
bool isValid(ll x,ll y,ll n,ll m){
    return (x>=0 and y>=0 and x<n and y<m);
}
ll power(ll a,ll n,ll m){
    ll ans=1;
    while(n>0){
        if(n&1){
            ans=(ans%m * a%m)%m;
        }
        n=n>>1;
        a=(a%m*a%m)%m;
    }
    return ans;
}
ll MMI(ll a,ll m){
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1){
        ll q=a/m,t=m;
        m=a%m,a=t,t=y,y=x-q*y,x=t;
    }
    if(x<0) x+=m0;
    return x;
}

ll dx[]={-1,1,0,0},dy[]={0,0,-1,1};
//ll dx[]={-1,1,-1,1,0,0,-1,1} , dy[]={-1,1,0,0,-1,1,1,-1};
int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    fast;
    ll n,w;
    cin>>n>>w;
    arr a;
    ll sum=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        sum+=x;
        a.pb(sum);
    }
    sort(all(a));
    ll mx=a.back();
    ll mn=a[0];
    if(mx>=0 and mn>=0){
        if(w>=mx)
            cout<<w-mx+1<<endl;
        else{
            cout<<0<<endl;
        }
    }else if(mn<=0 and mx<=0){
        if(w>=abs(mn))
            cout<<w-abs(mn)+1<<endl;
        else{
            cout<<0<<endl;
        }
    }else if(mn<=0 and mx>=0){
        if(w-mx>=abs(mn))
            cout<<w-mx-abs(mn)+1<<endl;
        else{
            cout<<0<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//template<typename T>
#define o_set(T) tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//use it like o_set(ll) x;  --> x.order.....
//-->for pair<ll,ll> : second element as index and for search use INT_MAX...
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

#define fast ios::sync_with_stdio(false);cin.tie(0);cout<<setprecision(25)
#define pb push_back
#define I insert
#define F first
#define S second
#define digit(x) floor(log10(x))+1
const long long M1=1000000007;
const long long  M2=998244353;
#define L_MAX 1e18
using ll = long long;
using ld = long double;
using ii = pair<ll,ll>;
using matrix = vector<vector<ll>>;
using arr = vector<ll>;
using vs = vector<string>;
using pv = vector<ii>;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
template<typename T>
void showArr(T a){
    for(auto i : a) cout<<i<<" ";
    cout<<endl;
}
bool isValid(ll x,ll y,ll n,ll m){
    return (x>=0 and y>=0 and x<n and y<m);
}
ll power(ll a,ll n,ll m){
    ll ans=1;
    while(n>0){
        if(n&1){
            ans=(ans%m * a%m)%m;
        }
        n=n>>1;
        a=(a%m*a%m)%m;
    }
    return ans;
}
ll MMI(ll a,ll m){
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1){
        ll q=a/m,t=m;
        m=a%m,a=t,t=y,y=x-q*y,x=t;
    }
    if(x<0) x+=m0;
    return x;
}

ll dx[]={-1,1,0,0},dy[]={0,0,-1,1};
//ll dx[]={-1,1,-1,1,0,0,-1,1} , dy[]={-1,1,0,0,-1,1,1,-1};
int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    fast;
    ll n,w;
    cin>>n>>w;
    arr a;
    ll sum=0,mx=0,mn1=INT_MAX;;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        sum+=x;
        a.pb(x);
        mn1=min(mn1,sum);
        mx=max(mx,sum);
    }
    auto is_possible1 = [&](ll m)->bool{
        ll md=w-mx;
        ll mn=md-m+1;
        bool ok=1;
        ll s=mn;
        for(auto i : a){
            s+=i;
            ok&=(s<=w and s>=0);
        }
        s=md;
        for(auto i : a){
            s+=i;
            ok&=(s<=w and s>=0);
        }
        return ok and md>=0 and mn>=0;
    };
    auto is_possible2 = [&](ll m)->bool{
        ll md=abs(mn1);
        ll mn=md-1+m;
        bool ok=1;
        ll s=mn;
        for(auto i : a){
            s+=i;
            ok&=(s<=w and s>=0);
        }
        s=md;
        for(auto i : a){
            s+=i;
            ok&=(s<=w and s>=0);
        }
        return ok and mn<=w and md<=w and md>=0 and mn>=0;
    };
    ll l=0,r=w+1,ans=0;
    while(l<=r){
        ll mid=(l+r)/2;
        if(is_possible1(mid) or is_possible2(mid)){
            ans=mid;
            l=mid+1;
        }else{
            r=mid-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//template<typename T>
#define o_set(T) tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//use it like o_set(ll) x;  --> x.order.....
//-->for pair<ll,ll> : second element as index and for search use INT_MAX...
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

#define fast ios::sync_with_stdio(false);cin.tie(0);cout<<setprecision(25)
#define pb push_back
#define I insert
#define F first
#define S second
#define digit(x) floor(log10(x))+1
const long long M1=1000000007;
const long long  M2=998244353;
#define L_MAX 1e18
using ll = long long;
using ld = long double;
using ii = pair<ll,ll>;
using matrix = vector<vector<ll>>;
using arr = vector<ll>;
using vs = vector<string>;
using pv = vector<ii>;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
template<typename T>
void showArr(T a){
    for(auto i : a) cout<<i<<" ";
    cout<<endl;
}
bool isValid(ll x,ll y,ll n,ll m){
    return (x>=0 and y>=0 and x<n and y<m);
}
ll power(ll a,ll n,ll m){
    ll ans=1;
    while(n>0){
        if(n&1){
            ans=(ans%m * a%m)%m;
        }
        n=n>>1;
        a=(a%m*a%m)%m;
    }
    return ans;
}
ll MMI(ll a,ll m){
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1){
        ll q=a/m,t=m;
        m=a%m,a=t,t=y,y=x-q*y,x=t;
    }
    if(x<0) x+=m0;
    return x;
}

ll dx[]={-1,1,0,0},dy[]={0,0,-1,1};
//ll dx[]={-1,1,-1,1,0,0,-1,1} , dy[]={-1,1,0,0,-1,1,1,-1};
int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    fast;
    ll n,w;
    cin>>n>>w;
    arr a;
    ll sum=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        a.pb(sum+x);
        sum+=x;
    }
    sort(all(a));
    ll mn=a[0];
    ll mx=a.back();
    ll ans=0;
    if(mn<0){
        if(w-mx>=abs(mn)){
            ans+=w-mx-abs(mn)+1;
        }else{
            ans=0;
        }
    }else{
        if(mx>w){
            ans=0;
        }else{
            ans+=w-mx+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//template<typename T>
#define o_set(T) tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//use it like o_set(ll) x;  --> x.order.....
//-->for pair<ll,ll> : second element as index and for search use INT_MAX...
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

#define fast ios::sync_with_stdio(false);cin.tie(0);cout<<setprecision(25)
#define pb push_back
#define I insert
#define F first
#define S second
#define digit(x) floor(log10(x))+1
const long long M1=1000000007;
const long long  M2=998244353;
#define L_MAX 1e18
using ll = long long;
using ld = long double;
using ii = pair<ll,ll>;
using matrix = vector<vector<ll>>;
using arr = vector<ll>;
using vs = vector<string>;
using pv = vector<ii>;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
template<typename T>
void showArr(T a){
    for(auto i : a) cout<<i<<" ";
    cout<<endl;
}
bool isValid(ll x,ll y,ll n,ll m){
    return (x>=0 and y>=0 and x<n and y<m);
}
ll power(ll a,ll n,ll m){
    ll ans=1;
    while(n>0){
        if(n&1){
            ans=(ans%m * a%m)%m;
        }
        n=n>>1;
        a=(a%m*a%m)%m;
    }
    return ans;
}
ll MMI(ll a,ll m){
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1){
        ll q=a/m,t=m;
        m=a%m,a=t,t=y,y=x-q*y,x=t;
    }
    if(x<0) x+=m0;
    return x;
}

ll dx[]={-1,1,0,0},dy[]={0,0,-1,1};
//ll dx[]={-1,1,-1,1,0,0,-1,1} , dy[]={-1,1,0,0,-1,1,1,-1};
int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    fast;
    ll n,w;
    cin>>n>>w;
    arr a;
    ll sum=0,mx=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        sum+=x;
        a.pb(x);
        mx=max(mx,sum);
    }
    auto is_possible = [&](ll m)->bool{
        ll md=w-mx;
        ll mn=md-m+1;
        bool ok=1;
        ll s=mn;
        for(auto i : a){
            s+=i;
            ok&=(s<=w and s>=0);
        }
        s=md;
        for(auto i : a){
            s+=i;
            ok&=(s<=w and s>=0);
        }
        return ok and md>=0 and mn>=0;
    };
    ll l=0,r=w+1,ans=0;
    while(l<=r){
        ll mid=(l+r)/2;
        if(is_possible(mid)){
            ans=mid;
            l=mid+1;
        }else{
            r=mid-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//template<typename T>
#define o_set(T) tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//use it like o_set(ll) x;  --> x.order.....
//-->for pair<ll,ll> : second element as index and for search use INT_MAX...
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

#define fast ios::sync_with_stdio(false);cin.tie(0);cout<<setprecision(25)
#define pb push_back
#define I insert
#define F first
#define S second
#define digit(x) floor(log10(x))+1
const long long M1=1000000007;
const long long  M2=998244353;
#define L_MAX 1e18
using ll = long long;
using ld = long double;
using ii = pair<ll,ll>;
using matrix = vector<vector<ll>>;
using arr = vector<ll>;
using vs = vector<string>;
using pv = vector<ii>;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
template<typename T>
void showArr(T a){
    for(auto i : a) cout<<i<<" ";
    cout<<endl;
}
bool isValid(ll x,ll y,ll n,ll m){
    return (x>=0 and y>=0 and x<n and y<m);
}
ll power(ll a,ll n,ll m){
    ll ans=1;
    while(n>0){
        if(n&1){
            ans=(ans%m * a%m)%m;
        }
        n=n>>1;
        a=(a%m*a%m)%m;
    }
    return ans;
}
ll MMI(ll a,ll m){
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1){
        ll q=a/m,t=m;
        m=a%m,a=t,t=y,y=x-q*y,x=t;
    }
    if(x<0) x+=m0;
    return x;
}

ll dx[]={-1,1,0,0},dy[]={0,0,-1,1};
//ll dx[]={-1,1,-1,1,0,0,-1,1} , dy[]={-1,1,0,0,-1,1,1,-1};
int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    fast;
    ll n,w;
    cin>>n>>w;
    arr a;
    ll sum=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        a.pb(sum+x);
        sum+=x;
    }
    sort(all(a));
    ll mn=a[0];
    ll mx=a.back();
    ll ans=0;
    if(mn<0)
        ans+=abs(w-mx)-abs(mn)+1;
    else{
        ans+=abs(w-mx)+1;
    }
    if(ans<0)
        ans=0;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//template<typename T>
#define o_set(T) tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//use it like o_set(ll) x;  --> x.order.....
//-->for pair<ll,ll> : second element as index and for search use INT_MAX...
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

#define fast ios::sync_with_stdio(false);cin.tie(0);cout<<setprecision(25)
#define pb push_back
#define I insert
#define F first
#define S second
#define digit(x) floor(log10(x))+1
const long long M1=1000000007;
const long long  M2=998244353;
#define L_MAX 1e18
using ll = long long;
using ld = long double;
using ii = pair<ll,ll>;
using matrix = vector<vector<ll>>;
using arr = vector<ll>;
using vs = vector<string>;
using pv = vector<ii>;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
template<typename T>
void showArr(T a){
    for(auto i : a) cout<<i<<" ";
    cout<<endl;
}
bool isValid(ll x,ll y,ll n,ll m){
    return (x>=0 and y>=0 and x<n and y<m);
}
ll power(ll a,ll n,ll m){
    ll ans=1;
    while(n>0){
        if(n&1){
            ans=(ans%m * a%m)%m;
        }
        n=n>>1;
        a=(a%m*a%m)%m;
    }
    return ans;
}
ll MMI(ll a,ll m){
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1){
        ll q=a/m,t=m;
        m=a%m,a=t,t=y,y=x-q*y,x=t;
    }
    if(x<0) x+=m0;
    return x;
}

ll dx[]={-1,1,0,0},dy[]={0,0,-1,1};
//ll dx[]={-1,1,-1,1,0,0,-1,1} , dy[]={-1,1,0,0,-1,1,1,-1};
int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    fast;
    ll n,w;
    cin>>n>>w;
    arr a;
    ll sum=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        a.pb(sum+x);
        sum+=x;
    }
    sort(all(a));
    ll mn=a[0];
    ll mx=a.back();
    ll ans=0;
    if(mn<0)
        ans+=abs(w-mx)-abs(mn)+1;
    else{
        ans+=abs(w-mx)+1;
    }
    if(ans<0 or mx>w)
        ans=0;
    cout<<ans<<endl;
    return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iterator>
#include <queue>
#include <cstdio>
#include <iomanip>

#define ll long long
#define ld long double
#define dbl double
#define bdl double
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using namespace std;
const int INF = (int)1e9 + 7;

inline void input() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef _DEBUG
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
}

int main() {
	input();
	int n, w;
	cin >> n >> w;
	vector<ll> pref(n);
	ll mx = -INF, mn = INF;
	for (int i = 0; i < n; i++) {
		cin >> pref[i];
		if (i > 0)
			pref[i] = pref[i - 1] + pref[i];
		mn = min(pref[i], mn);
		mx = max(pref[i], mx);
	}
	if (mn <= 0 && mx >= 0 && abs(mx) <= w)
		cout << max(w - mx + mn + 1, 0);
	else if (mx >= 0 && abs(mx) <= w)
		cout << max(w - mx + 1, 0);
	else if (abs(w + mn + 1) <= w)
		cout << max(w + mn + 1, 0);
	else
		cout << 0;
	return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iterator>
#include <queue>
#include <cstdio>
#include <iomanip>

#define ll long long
#define ld long double
#define dbl double
#define bdl double
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using namespace std;
const int INF = (int)1e9 + 7;

inline void input() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef _DEBUG
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
}

int main() {
	input();
	int n, w;
	cin >> n >> w;
	vector<int> pref(n);
	int mx = -INF, mn = INF;
	for (int i = 0; i < n; i++) {
		cin >> pref[i];
		if (i > 0)
			pref[i] = pref[i - 1] + pref[i];
		mn = min(pref[i], mn);
		mx = max(pref[i], mx);
	}
	if (mx > w) {
		cout << 0;
		return 0;
	}
	int l = 0, r = w;
	if (mn < 0)
		l = abs(mn);
	if (mx > 0)
		r = w - mx;
	if (l > r)
		cout << 0;
	else
		cout << r - l + 1;
	return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iterator>
#include <queue>
#include <cstdio>
#include <iomanip>

#define ll long long
#define ld long double
#define dbl double
#define bdl double
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using namespace std;
const int INF = (int)1e9 + 7;

inline void input() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef _DEBUG
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
}

int main() {
	input();
	int n, w;
	cin >> n >> w;
	vector<ll> pref(n);
	ll mx = -INF, mn = INF;
	for (int i = 0; i < n; i++) {
		cin >> pref[i];
		if (i > 0)
			pref[i] = pref[i - 1] + pref[i];
		mn = min(pref[i], mn);
		mx = max(pref[i], mx);
	}
	if (mn <= 0 && mx >= 0 && abs(mx) <= n)
		cout << w - mx + mn + 1;
	else if (mx >= 0 && abs(mx) <= n)
		cout << w - mx + 1;
	else if (abs(mn) <= n)
		cout << w + mn + 1;
	else
		cout << 0;
	return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iterator>
#include <queue>
#include <cstdio>
#include <iomanip>

#define ll long long
#define ld long double
#define dbl double
#define bdl double
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using namespace std;
const int INF = (int)1e9 + 7;

inline void input() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef _DEBUG
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
}

int main() {
	input();
	int n, w;
	cin >> n >> w;
	vector<int> pref(n);
	int mx = -INF, mn = INF;
	for (int i = 0; i < n; i++) {
		cin >> pref[i];
		if (i > 0)
			pref[i] = pref[i - 1] + pref[i];
		mn = min(pref[i], mn);
		mx = max(pref[i], mx);
	}
	if (mn <= 0 && mx >= 0 && abs(mx) <= w)
		cout << max(w - mx + mn + 1, 0);
	else if (mx >= 0 && abs(mx) <= w)
		cout << max(w - mx + 1, 0);
	else if (abs(w + mn + 1) <= w)
		cout << max(w + mn + 1, 0);
	else
		cout << 0;
	return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iterator>
#include <queue>
#include <cstdio>
#include <iomanip>

#define ll long long
#define ld long double
#define dbl double
#define bdl double
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using namespace std;
const int INF = (int)1e9 + 7;

inline void input() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef _DEBUG
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
}

int main() {
	input();
	int n, w;
	cin >> n >> w;
	vector<ll> pref(n);
	ll mx = -INF, mn = INF;
	for (int i = 0; i < n; i++) {
		cin >> pref[i];
		if (i > 0)
			pref[i] = pref[i - 1] + pref[i];
		mn = min(pref[i], mn);
		mx = max(pref[i], mx);
	}
	if (mn <= 0 && mx >= 0)
		cout << w - mx + mn + 1;
	else if (mx >= 0)
		cout << w - mx + 1;
	else
		cout << w + mn + 1;
	return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iterator>
#include <queue>
#include <cstdio>
#include <iomanip>

#define ll long long
#define ld long double
#define dbl double
#define bdl double
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using namespace std;
const int INF = (int)1e9 + 7;

inline void input() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef _DEBUG
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
}

int main() {
	input();
	int n, w;
	cin >> n >> w;
	vector<ll> pref(n);
	ll mx = -INF, mn = INF;
	for (int i = 0; i < n; i++) {
		cin >> pref[i];
		if (i > 0)
			pref[i] = pref[i - 1] + pref[i];
		mn = min(pref[i], mn);
		mx = max(pref[i], mx);
	}
	if (mn <= 0 && mx >= 0 && abs(mx) < n)
		cout << w - mx + mn + 1;
	else if (mx >= 0 && abs(mx) < n)
		cout << w - mx + 1;
	else if (abs(mn) < n)
		cout << w + mn + 1;
	else
		cout << 0;
	return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iterator>
#include <queue>
#include <cstdio>
#include <iomanip>

#define ll long long
#define ld long double
#define dbl double
#define bdl double
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using namespace std;
const int INF = (int)1e9 + 7;

inline void input() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef _DEBUG
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
}

int main() {
	input();
	int n, w;
	cin >> n >> w;
	vector<ll> pref(n);
	ll mx = -INF, mn = INF;
	for (int i = 0; i < n; i++) {
		cin >> pref[i];
		if (i > 0)
			pref[i] = pref[i - 1] + pref[i];
		mn = min(pref[i], mn);
		mx = max(pref[i], mx);
	}
	if (mn <= 0 && mx >= 0 && abs(mx) <= w)
		cout << w - mx + mn + 1;
	else if (mx >= 0 && abs(mx) <= w)
		cout << w - mx + 1;
	else if (abs(mn) <= w)
		cout << w + mn + 1;
	else
		cout << 0;
	return 0;
}


#include<stdio.h>
#include<algorithm>
using std::sort;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mabs(x) ((x)>0?(x):(0-(x)))
#define N_max 1003

typedef long long ll;
ll n,w, a[N_max];
/*
ÿվ�����仯����¼y-x
*/

int main() {

    scanf("%lld %lld", &n,&w); a[0] = 0;
    ll mi=1000000009, ma=0;
    for (int i = 1; i <= n; ++i)
    {
        scanf("%lld", &a[i]);
        a[i] += a[i - 1];
        mi = min(a[i], mi);
        ma = max(a[i], ma);
    }
    ll l, r;
    //�������㲻��ʽ��l��r
    if (mi < 0)l = 0 - mi;
    else l = 0;
    if (ma < 0)r = w;
    else r = w - ma;
    if (l <= r)printf("%lld", r - l + 1);
    else printf("0");
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
typedef long long ll;
ll stop[maxn],w,pre,ans,l,r,ma,mi;
int n;

int main(){

	cin >> n >> w ;
	pre = 0,ma = 0;
	for(int i=1;i<=n;i++){
    	cin >> stop[i];
    }
	for(int i=1;i<=n;i++){

		pre = pre + stop[i];
		if(pre > ma)ma = pre;
		else if(pre <mi)mi = pre;
	}
    if (mi < 0)l = 0 - mi;
    else l = 0;
    if (ma < 0)r = w;
    else r = w - ma;
    ans = r -l + 1;
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;

long stop[maxn],w,pre,ans,ma,min;
int n;

int main(){

	cin >> n >> w ;
	pre = 0,ma = 0;
	for(int i=1;i<=n;i++){
    	cin >> stop[i];
    }
	for(int i=1;i<=n;i++){

		pre = pre + stop[i];
		if(pre > ma)ma = pre;
	}
	ans = w-ma+1;
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
typedef long long ll;
ll stop[maxn],w,pre,ans,l,r,ma,mi;

int n;

int main(){

	cin >> n >> w ;
	pre = 0,ma = 0,mi = 100000000;
	stop[0]=0;
	for(int i=1;i<=n;i++){
    	cin >> stop[i];
    }
	for(int i=1;i<=n;i++){

		pre = pre + stop[i];
		if(pre > ma)ma = pre;
		else if(pre <mi)mi = pre;
	}
    if (mi < 0)l = 0 - mi;
    else l = 0;
    if (ma < 0)r = w;
    else r = w - ma;
    ans = r -l + 1;
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
typedef long long ll;
ll stop[maxn],w,pre,ans,l,r,ma,mi;

int n;

int main(){

	cin >> n >> w ;
	pre = 0,ma = 0,mi = 100000000;
	stop[0]=0;
	for(int i=1;i<=n;i++){
    	cin >> stop[i];
    }
	for(int i=1;i<=n;i++){

		pre = pre + stop[i];
		if(pre > ma)ma = pre;
		else if(pre <mi)mi = pre;
	}
    if (mi < 0)l = 0 - mi;
    else l = 0;
    if (ma < 0)r = w;
    else r = w - ma;
    ans = r -l + 1;
    if(l <= r)	cout << ans << endl;
    else cout << 0 << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
typedef long long ll;
ll stop[maxn],w,pre,ans,ma,min;
int n;

int main(){

	cin >> n >> w ;
	pre = 0,ma = 0;
	for(int i=1;i<=n;i++){
    	cin >> stop[i];
    }
	for(int i=1;i<=n;i++){

		pre = pre + stop[i];
		if(pre > ma)ma = pre;
	}
	ans = w-ma+1;
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
typedef long long ll;
ll stop[maxn],w,pre,ans,l,r,ma,mi;

int n;

int main(){

	cin >> n >> w ;
	pre = 0,ma = 0;
	stop[0]=0;
	for(int i=1;i<=n;i++){
    	cin >> stop[i];
    }
	for(int i=1;i<=n;i++){

		pre = pre + stop[i];
		if(pre > ma)ma = pre;
		else if(pre <mi)mi = pre;
	}
    if (mi < 0)l = 0 - mi;
    else l = 0;
    if (ma < 0)r = w;
    else r = w - ma;
    ans = r -l + 1;
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define sz(a)	ll(a.size())
typedef long long ll;
typedef long double ld;
map<ll,ll> counter;
std::vector<ll> a(1002);
ll fastexpo(ll x,ll y,ll m){ll temp=1;while(y>0){if(y&1)temp = ((temp%m)*(x%m))%m;x = ((x%m)*(x%m))%m;y>>=1;}return temp;}
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll cur,n,w,ans=0;
	 	cin>>n>>w;
	 	FOR(i,0,n)cin>>a[i];
	 	ans=w;
	 	ll k=0;
	 	cur=w;
	 	while(k<n && ans>0)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		// cout<<cur<<" "<<ans<<endl;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans-1;
	 			ans--;
	 		}
	 	}
	 	if(ans<0){cout<<"0";return 0;}
	 	ll up=ans;
	 	ans=0,k=0;
	 	cur=0;
	 	while(k<n)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		// cout<<cur<<" "<<ans<<endl;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans+1;
	 			ans++;
	 		}
	 	}
	 	ll down=ans;
	 	// cout<<up<<" "<<down<<endl;
		cout<<up-down+1<<ln;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define sz(a)	ll(a.size())
typedef long long ll;
typedef long double ld;
map<ll,ll> counter;
std::vector<ll> a(1002);
ll fastexpo(ll x,ll y,ll m){ll temp=1;while(y>0){if(y&1)temp = ((temp%m)*(x%m))%m;x = ((x%m)*(x%m))%m;y>>=1;}return temp;}
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll cur,n,w,ans=0;
	 	cin>>n>>w;
	 	FOR(i,0,n)cin>>a[i];
	 	ans=w;
	 	ll k=0;
	 	{
	 		if(a[0]<0){cur=ans+a[0];ans=ans+a[0];}
	 	}
	 	while(k<n)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		if(cur>w)
	 		{
	 			k=0;
	 			cur=ans-1;
	 			ans--;
	 		}
	 	}
	 	cout<<ans+1<<ln;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define sz(a)	ll(a.size())
typedef long long ll;
typedef long double ld;
map<ll,ll> counter;
std::vector<ll> a(1002);
ll fastexpo(ll x,ll y,ll m){ll temp=1;while(y>0){if(y&1)temp = ((temp%m)*(x%m))%m;x = ((x%m)*(x%m))%m;y>>=1;}return temp;}
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll cur,n,w,ans=0;
	 	cin>>n>>w;
	 	FOR(i,0,n)cin>>a[i];
	 	ans=w;
	 	ll k=0;
	 	cur=w;
	 	while(k<n && ans>0)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans-1;
	 			ans--;
	 		}
	 	}
	 	if(ans<0){cout<<"0";return 0;}
	 	ll up=ans;
	 	ans=0,k=0;
	 	cur=0;
	 	while(k<n && ans<10000000)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans+1;
	 			ans++;
	 		}
	 	}
	 	if(ans>=10000000){cout<<"0";return 0;}
	 	ll down=ans;
	 	ll temp=0;
		cout<<max(up-down+1,temp)<<ln;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define sz(a)	ll(a.size())
typedef long long ll;
typedef long double ld;
map<ll,ll> counter;
std::vector<ll> a(1002);
ll fastexpo(ll x,ll y,ll m){ll temp=1;while(y>0){if(y&1)temp = ((temp%m)*(x%m))%m;x = ((x%m)*(x%m))%m;y>>=1;}return temp;}
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll cur,n,w,ans=0;
	 	cin>>n>>w;
	 	FOR(i,0,n)cin>>a[i];
	 	ans=w;
	 	ll k=0;
	 	cur=w;
	 	while(k<n && ans>0)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans-1;
	 			ans--;
	 		}
	 	}
	 	if(ans<0){cout<<"0";return 0;}
	 	ll up=ans;
	 	ans=0,k=0;
	 	cur=0;
	 	while(k<n && ans<=up)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans+1;
	 			ans++;
	 		}
	 	}
	 	if(ans>=up){cout<<"0";return 0;}
	 	ll down=ans;
	 	ll temp=0;
		cout<<max(up-down+1,temp)<<ln;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define sz(a)	ll(a.size())
typedef long long ll;
typedef long double ld;
map<ll,ll> counter;
std::vector<ll> a(1002);
	 	ll cur,n,w,ans=0;
ll fastexpo(ll x,ll y,ll m){ll temp=1;while(y>0){if(y&1)temp = ((temp%m)*(x%m))%m;x = ((x%m)*(x%m))%m;y>>=1;}return temp;}
int func(ll l,ll r,ll mid);
int funcu(ll t)
{
	if(t>w)
		return 0;
	FOR(i,0,n)
	{
		t+=a[i];
		if(t>w)return 0;
	}
	return 1;
}

int funcl(ll t)
{
	if(t<0)return 0;
	FOR(i,0,n)
	{
		t+=a[i];
		if(t<0)return 0;
	}
	return 1;
}
ll bsl(int l,int r)
{

	int temp;
	int mid=(l+r)/2;
	if(l>=r)
	{
		if(funcl(l))return l;
		else return l+1;
	}
	if(!funcl(mid))
		return bsl(mid+1,r);
	else return bsl(l,mid);
}
ll bsu(int l,int r)
{
	int temp;
	int mid=(l+r)/2;
	if(l>=r)
	{
		if(funcu(l))return l;
		else return l-1;
	}
	if(funcu(mid))
		return bsu(mid+1,r);
	else return bsu(l,mid);
}
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	cin>>n>>w;
	 	FOR(i,0,n)cin>>a[i];
	 	ll a=bsu(0,1e9);
	 	ll b=bsl(0,1e9);
	 	cout<<max(ll(0),a-b+1);
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define sz(a)	ll(a.size())
typedef long long ll;
typedef long double ld;
map<ll,ll> counter;
std::vector<ll> a(1002);
ll fastexpo(ll x,ll y,ll m){ll temp=1;while(y>0){if(y&1)temp = ((temp%m)*(x%m))%m;x = ((x%m)*(x%m))%m;y>>=1;}return temp;}
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll cur,n,w,ans=0;
	 	cin>>n>>w;
	 	FOR(i,0,n)cin>>a[i];
	 	ans=w;
	 	ll k=0;
	 	cur=w;
	 	while(k<n && ans>0)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans-1;
	 			ans--;
	 		}
	 	}
	 	if(ans<=0){cout<<"0";return 0;}
	 	// ans=up;
	 	ll down=0;
	 	// while(k<n)
	 	// {
	 	// 	cur=a[k]+cur;
	 	// 	k++;
	 	// 	if(cur>w || cur<0)
	 	// 	{
	 	// 		if(ans>=up){cout<<"0";return 0;}
	 	// 	}
	 	// }
	 	// ll up=ans;
	 	// ans=0,k=0;
	 	// cur=0;
	 	// while(k<n && ans<=up)
	 	// {
	 	// 	cur=a[k]+cur;
	 	// 	k++;
	 	// 	if(cur>w || cur<0)
	 	// 	{
	 	// 		k=0;
	 	// 		cur=ans+1;
	 	// 		ans++;
	 	// 	}
	 	// }
	 	// if(ans>=up){cout<<"0";return 0;}
	 	// ll down=ans;
	 	ll temp=0;
		cout<<max(ans,temp)<<ln;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define sz(a)	ll(a.size())
typedef long long ll;
typedef long double ld;
map<ll,ll> counter;
std::vector<ll> a(1002);
ll fastexpo(ll x,ll y,ll m){ll temp=1;while(y>0){if(y&1)temp = ((temp%m)*(x%m))%m;x = ((x%m)*(x%m))%m;y>>=1;}return temp;}
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll cur,n,w,ans=0;
	 	cin>>n>>w;
	 	FOR(i,0,n)cin>>a[i];
	 	ans=w;
	 	ll k=0;
	 	cur=w;
	 	while(k<n)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		// cout<<cur<<" "<<ans<<endl;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans-1;
	 			ans--;
	 		}
	 	}
	 	ll up=ans;
	 	ans=0,k=0;
	 	cur=0;
	 	while(k<n)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		// cout<<cur<<" "<<ans<<endl;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans+1;
	 			ans++;
	 		}
	 	}
	 	ll down=ans;
	 	// cout<<up<<" "<<down<<endl;
		cout<<up-down+1<<ln;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define sz(a)	ll(a.size())
typedef long long ll;
typedef long double ld;
map<ll,ll> counter;
std::vector<ll> a(1002);
ll fastexpo(ll x,ll y,ll m){ll temp=1;while(y>0){if(y&1)temp = ((temp%m)*(x%m))%m;x = ((x%m)*(x%m))%m;y>>=1;}return temp;}
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll cur,n,w,ans=0;
	 	cin>>n>>w;
	 	FOR(i,0,n)cin>>a[i];
	 	ans=w;
	 	ll k=0;
	 	cur=w;
	 	while(k<n && ans>0)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		// cout<<cur<<" "<<ans<<endl;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans-1;
	 			ans--;
	 		}
	 	}
	 	// cout<<"sa";
	 	if(ans<0){cout<<"0";return 0;}
	 	ll up=ans;
	 	ans=0,k=0;
	 	cur=0;
	 	while(k<n && ans<1000000)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		// cout<<cur<<" "<<ans<<endl;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans+1;
	 			ans++;
	 		}
	 	}
	 	if(ans>=1000000){cout<<"0";return 0;}
	 	ll down=ans;
	 	// cout<<up<<" "<<down<<endl;
	 	ll temp=0;
		cout<<max(up-down+1,temp)<<ln;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define sz(a)	ll(a.size())
typedef long long ll;
typedef long double ld;
map<ll,ll> counter;
std::vector<ll> a(1002);
ll fastexpo(ll x,ll y,ll m){ll temp=1;while(y>0){if(y&1)temp = ((temp%m)*(x%m))%m;x = ((x%m)*(x%m))%m;y>>=1;}return temp;}
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll cur,n,w,ans=0;
	 	cin>>n>>w;
	 	FOR(i,0,n)cin>>a[i];
	 	ans=w;
	 	ll k=0;
	 	cur=w;
	 	while(k<n && ans>0)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		// cout<<cur<<" "<<ans<<endl;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans-1;
	 			ans--;
	 		}
	 	}
	 	// cout<<"sa";
	 	if(ans<0){cout<<"0";return 0;}
	 	ll up=ans;
	 	ans=0,k=0;
	 	cur=0;
	 	while(k<n && ans<1000000)
	 	{
	 		cur=a[k]+cur;
	 		k++;
	 		// cout<<cur<<" "<<ans<<endl;
	 		if(cur>w || cur<0)
	 		{
	 			k=0;
	 			cur=ans+1;
	 			ans++;
	 		}
	 	}
	 	if(ans>=1000000){cout<<"0";return 0;}
	 	ll down=ans;
	 	// cout<<up<<" "<<down<<endl;
		cout<<up-down+1<<ln;
		return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int
#define ff first
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse
#define itr iterator
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

    ll n,k;
    cin>>n>>k;

    vl v(n);
    cin>>v[0];
    v[0] += k;
    ll maxi = max((ll)0,k-v[0]);
    ll mini = min(infinity,2*k-v[0]);
    forn(i,1,n)
    {
        cin>>v[i];
        v[i] += v[i-1];
        if(v[i] < 0)
        {
            cout<<0;
            return 0;
        }
        maxi = max(maxi,k-v[i]);
        mini = min(mini,2*k-v[i]);
    }

    mini = min(mini,k);
    // cout<<maxi<<" "<<mini<<endl;

    if(mini < 0) cout<<0;
    else
    {
        cout<<(mini-maxi+1);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int
#define ff first
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse
#define itr iterator
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

    int n,k;
    cin>>n>>k;

    vi v(n);
    cin>>v[0];
    forn(i,1,n)
    {
        cin>>v[i];
        v[i] += v[i-1];
    }

    int mini = imx;
    forn(i,0,n)
    {
        if(v[i] > 0)
        {
            if(k < v[i])
            {
                cout<<0;
                return 0;
            }
            else
            {
                mini = min(1+k-v[i],mini);
            }
        }
        else
        {
            if(abs(v[i]) > k)
            {
                return 0;
            }
            else
            {
                mini = min(1+k-abs(v[i]),mini);
            }
        }

    }

    cout<<mini;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int
#define ff first
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse
#define itr iterator
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

    int n,k;
    cin>>n>>k;

    vi v(n);
    cin>>v[0];
    forn(i,1,n)
    {
        cin>>v[i];
        v[i] += v[i-1];
    }

    int idx = -1;
    int minim = imx;
    forn(i,0,n)
    {
        if(v[i] < 0)
        {
            if(abs(v[i]) > k)
            {
                cout<<0;
                return 0;
            }
            else
            {
                if(minim > v[i])
                {
                    minim = v[i];
                    idx = i;
                }
            }
        }

    }

    if(idx == -1)
    {
        idx = 0;
        minim = 0;
    }

    int i = idx;
    int mini = imx;
    for(; i < n; i++)
    {
        v[i] += abs(minim);
        mini = min(mini,1+k-v[i]);
    }

    if(mini < 0) cout<<0;
    else cout<<mini;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int
#define ff first
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse
#define itr iterator
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

    ll n,k;
    cin>>n>>k;

    vl v(n);
    cin>>v[0];
    v[0] += k;
    ll maxi = max((ll)0,k-v[0]);
    ll mini = min(infinity,2*k-v[0]);
    forn(i,1,n)
    {
        cin>>v[i];
        v[i] += v[i-1];
        if(v[i] < 0)
        {
            cout<<0;
            return 0;
        }
        maxi = max(maxi,k-v[i]);
        mini = min(mini,2*k-v[i]);
    }

    mini = min(mini,k);
    // cout<<maxi<<" "<<mini<<endl;

    if(mini < 0) cout<<0;
    else if((mini-maxi+1) < 0)
    {
        cout<<0;
    }
    else
    {
        cout<<(mini-maxi+1);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int
#define ff first
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse
#define itr iterator
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

    int n,k;
    cin>>n>>k;

    vi v(n);
    cin>>v[0];
    forn(i,1,n)
    {
        cin>>v[i];
        v[i] += v[i-1];
    }

    int idx = -1;
    int minim = imx;
    forn(i,0,n)
    {
        if(v[i] < 0)
        {
            if(abs(v[i]) > k)
            {
                return 0;
            }
            else
            {
                if(minim > v[i])
                {
                    minim = v[i];
                    idx = i;
                }
            }
        }

    }

    int mini = 1+k-abs(minim);
    if(idx == -1)
    {
        idx = 0;
        minim = 0;
        mini = imx;
    }

    int i = idx;
    for(; i < n; i++)
    {
        v[i] += abs(minim);
        mini = min(mini,1+k-v[i]);
    }

    if(mini < 0) cout<<0;
    else cout<<mini;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int
#define ff first
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse
#define itr iterator
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

    int n,k;
    cin>>n>>k;

    vi v(n);
    cin>>v[0];
    forn(i,1,n)
    {
        cin>>v[i];
        v[i] += v[i-1];
    }

    int idx = -1;
    int minim = imx;
    forn(i,0,n)
    {
        if(v[i] < 0)
        {
            if(abs(v[i]) > k)
            {
                cout<<0;
                return 0;
            }
            else
            {
                if(minim > v[i])
                {
                    minim = v[i];
                    idx = i;
                }
            }
        }
    }

    int mini = 1+k-abs(minim);
    if(idx == -1)
    {
        idx = 0;
        minim = 0;
        mini = imx;
    }

    int i = idx;
    for(; i < n; i++)
    {
        v[i] += abs(minim);
        mini = min(mini,1+k-v[i]);
    }

    if(mini < 0) cout<<0;
    else cout<<mini;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int
#define ff first
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse
#define itr iterator
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

    ll n,k;
    cin>>n>>k;

    vl v(n);
    cin>>v[0];
    forn(i,1,n)
    {
        cin>>v[i];
        v[i] += v[i-1];
    }

    int idx = -1;
    ll minim = infinity;
    forn(i,0,n)
    {
        if(v[i] < 0)
        {
            if(abs(v[i]) > k)
            {
                cout<<0;
                return 0;
            }
            else
            {
                if(minim > v[i])
                {
                    minim = v[i];
                    idx = i;
                }
            }
        }
    }

    ll mini = 1+k-abs(minim);
    if(idx == -1)
    {
        idx = 0;
        minim = 0;
        mini = imx;
    }

    int i = idx;
    for(; i < n; i++)
    {
        v[i] += abs(minim);
        mini = min(mini,1+k-v[i]);
    }

    if(mini < 0) cout<<0;
    else cout<<mini;

    return 0;
}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	IOS
	LL n,w;cin>>n>>w;
	vector<LL>A(n);
	for(LL i=0;i<n;i++)cin>>A[i];
	for(LL i=1;i<n;i++)A[i]+=A[i-1];
	LL mx=*max_element(A.begin(),A.end());
	LL mn=*min_element(A.begin(),A.end());
	if(mx>w || mn<0)
	{
		cout<<0;
		return 0;
	}
	LL MX=min(w-mx,w);
	LL MN=max((LL)0,-mn);
	cout<<abs(MX-MN)+1<<endl;

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	IOS
	LL n,w;cin>>n>>w;
	vector<LL>A(n);
	for(LL i=0;i<n;i++)
	{
		cin>>A[i];
		if(A[i]>2*w || A[i]<-2*w)
		{
			cout<<0;
			return 0;
		}
	}
	for(LL i=1;i<n;i++)A[i]+=A[i-1];
	LL mx=*max_element(A.begin(),A.end());
	LL mn=*min_element(A.begin(),A.end());
	if(mx>w || mn<-w)
	{
		cout<<0;
		return 0;
	}
	LL MX=w-mx;
	LL MN=-mn;
	if(MN<0)cout<<MX+1;
	else cout<<MX-MN+1;

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	IOS
	LL n,w;cin>>n>>w;
	vector<LL>A(n);
	for(LL i=0;i<n;i++)
	{
		cin>>A[i];
		if(A[i]>2*w || A[i]<-2*w)
		{
			cout<<0;
			return 0;
		}
	}
	for(LL i=1;i<n;i++)A[i]+=A[i-1];
	LL mx=*max_element(A.begin(),A.end());
	LL mn=*min_element(A.begin(),A.end());
	if(mx>w || mn<-w)
	{
		cout<<0;
		return 0;
	}
	LL MX=w-mx;
	LL MN=-mn;
	if(MN>=MX || MN<0)cout<<MX+1;
	else cout<<abs(MX-MN)+1;

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	IOS
	LL n,w;cin>>n>>w;
	vector<LL>A(n);
	for(LL i=0;i<n;i++)
	{
		cin>>A[i];
		if(A[i]>2*w || A[i]<-2*w)
		{
			cout<<0;
			return 0;
		}
	}
	for(LL i=1;i<n;i++)A[i]+=A[i-1];
	LL mx=*max_element(A.begin(),A.end());
	LL mn=*min_element(A.begin(),A.end());
	if(mx>w || mn<-w)
	{
		cout<<0;
		return 0;
	}
	LL MX=min(w-mx,w);
	LL MN=max((LL)0,-mn);
	cout<<abs(MX-MN)+1<<endl;

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	IOS
	LL n,w;cin>>n>>w;
	vector<LL>A(n);
	for(LL i=0;i<n;i++)cin>>A[i];
	for(LL i=1;i<n;i++)A[i]+=A[i-1];
	LL mx=*max_element(A.begin(),A.end());
	LL mn=*min_element(A.begin(),A.end());
	if(mx>w || mn<-w)
	{
		cout<<0;
		return 0;
	}
	LL MX=min(w-mx,w);
	LL MN=max((LL)0,-mn);
	cout<<abs(MX-MN)+1<<endl;

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	IOS
	LL n,w;cin>>n>>w;
	vector<LL>A(n);
	for(LL i=0;i<n;i++)
	{
		cin>>A[i];
	}
	for(LL i=1;i<n;i++)A[i]+=A[i-1];
	LL mn=0,mx=w;
	for(LL i=0;i<n;i++)
	{
		if(A[i]<0)mn=max(mn,-A[i]);
		if(A[i]>0)mx=min(mx,w-A[i]);

	}
	if(mn<=mx)cout<<mx-mn+1;
	else cout<<0;

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	IOS
	LL n,w;cin>>n>>w;
	vector<LL>A(n);
	for(LL i=0;i<n;i++)
	{
		cin>>A[i];
	}
	for(LL i=1;i<n;i++)A[i]+=A[i-1];
	LL mn=0,mx=w;
	for(LL i=0;i<n;i++)
	{
		if(A[i]<0)mn=max(mn,-A[i]);
		if(A[i]>0)mx=min(mx,w-A[i]);
		if(A[i]<-w || A[i]>w)
		{
			cout<<0;
			return 0;
		}
	}
	if(mn<=mx)cout<<mx-mn+1;
	else cout<<0;

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	IOS
	LL n,w;cin>>n>>w;
	vector<LL>A(n);
	for(LL i=0;i<n;i++)
	{
		cin>>A[i];
		if(A[i]>2*w || A[i]<-2*w)
		{
			cout<<0;
			return 0;
		}
	}
	for(LL i=1;i<n;i++)A[i]+=A[i-1];
	LL mx=*max_element(A.begin(),A.end());
	LL mn=*min_element(A.begin(),A.end());
	if(mx>w || mn<-w)
	{
		cout<<0;
		return 0;
	}
	LL MX=min(w-mx,w);
	LL MN=max((LL)0,-mn);
	cout<<(MX-MN)+1<<endl;

}


#include<bits/stdc++.h>
#define LL long long int
#define PI 3.14159265358979323846
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	IOS
	LL n,w;cin>>n>>w;
	vector<LL>A(n);
	for(LL i=0;i<n;i++)
	{
		cin>>A[i];
	}
	for(LL i=1;i<n;i++)A[i]+=A[i-1];
	LL mn=0,mx=w;
	for(LL i=0;i<n;i++)
	{
		if(A[i]<0)mn=max(mn,-A[i]);
		if(A[i]>0)mx=min(mx,w-A[i]);
		if(A[i]<-w || A[i]>w)
		{
			cout<<0;
			return 0;
		}
	}
	cout<<mx-mn+1;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

int ispal(string s){
    int len=s.size();
    int flag=1;
    for(int i=0;i<len;++i){
        if(s[i]!=s[len-i-1]){
            flag=0;break;
        }
    }
    return flag;
}

ll sroot(ll n,ll low=1,ll high=1e9+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid;
    if(a>n)return sroot(n,low,mid-1);
    else return sroot(n,mid,high);
}
ll croot(ll n,ll low=1,ll high=1e6+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid*mid;
    if(a>n)return croot(n,low,mid-1);
    else return croot(n,mid,high);

}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,w;cin>>n>>w;
	ll a[n];fo(i,n)cin>>a[i];
	ll l=0,r=w;

	ll dp[n];
	dp[0]=a[0];
	fo1(i,n-1)
	dp[i]=dp[i-1]+a[i];

	//fo(i,n)cout<<dp[i]<<" ";cout<<endl;
	ll f=0;
	fo(i,n)
	{
		ll x=dp[i];
		if(x!=0)
		{
			if(x>0 && r+x>w)
			r=(r+x-w);
			else if(x<0 && l-abs(x)<0)
			l=(l+abs(x));
		}
		if(r<0||l>w){
			f=1;break;
		}
		//cout<<l<<" "<<r<<endl;
	}
	if(f==1||(r<l)||(r-l+1)>w || (r-l+1)<0)cout<<"0";
	else
	cout<<(r-l)+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

int ispal(string s){
    int len=s.size();
    int flag=1;
    for(int i=0;i<len;++i){
        if(s[i]!=s[len-i-1]){
            flag=0;break;
        }
    }
    return flag;
}

ll sroot(ll n,ll low=1,ll high=1e9+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid;
    if(a>n)return sroot(n,low,mid-1);
    else return sroot(n,mid,high);
}
ll croot(ll n,ll low=1,ll high=1e6+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid*mid;
    if(a>n)return croot(n,low,mid-1);
    else return croot(n,mid,high);

}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,w;cin>>n>>w;
	ll a[n];fo(i,n)cin>>a[i];
	ll l=0,r=w;

	ll dp[n];
	dp[0]=a[0];
	fo1(i,n-1)
	dp[i]=dp[i-1]+a[i];

	//fo(i,n)cout<<dp[i]<<" ";cout<<endl;
	ll f=0;
	fo(i,n)
	{
		ll x=dp[i];
		if(x!=0)
		{
			if(x>0 && r+x>w)
			r=(w-x);
			else if(x<0 && l-abs(x)<0)
			l=(l+abs(x));
		}
		if(r<0||l>w){
			f=1;break;
		}
		//cout<<l<<" "<<r<<endl;
	}
	if(f==1||(r<l))cout<<"0";
	else
	cout<<(r-l)+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

int ispal(string s){
    int len=s.size();
    int flag=1;
    for(int i=0;i<len;++i){
        if(s[i]!=s[len-i-1]){
            flag=0;break;
        }
    }
    return flag;
}

ll sroot(ll n,ll low=1,ll high=1e9+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid;
    if(a>n)return sroot(n,low,mid-1);
    else return sroot(n,mid,high);
}
ll croot(ll n,ll low=1,ll high=1e6+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid*mid;
    if(a>n)return croot(n,low,mid-1);
    else return croot(n,mid,high);

}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,w;cin>>n>>w;
	ll a[n];fo(i,n)cin>>a[i];
	ll l=0,r=w;

	ll dp[n];
	dp[0]=a[0];
	fo1(i,n-1)
	dp[i]=dp[i-1]+a[i];

	//fo(i,n)cout<<dp[i]<<" ";cout<<endl;
	ll f=0;
	fo(i,n)
	{
		ll x=dp[i];
		if(x!=0)
		{
			if(x>0 && r+x>w)
			r=(w-x);
			else if(x<0 && l-abs(x)<0)
			l=(l+abs(x));
		}
		if(r<0||l>w){
			f=1;break;
		}
		//cout<<l<<" "<<r<<endl;
	}
	if(f==1||(r<l)||(r-l+1)>w || (r-l+1)<0)cout<<"0";
	else
	cout<<(r-l)+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

int ispal(string s){
    int len=s.size();
    int flag=1;
    for(int i=0;i<len;++i){
        if(s[i]!=s[len-i-1]){
            flag=0;break;
        }
    }
    return flag;
}

ll sroot(ll n,ll low=1,ll high=1e9+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid;
    if(a>n)return sroot(n,low,mid-1);
    else return sroot(n,mid,high);
}
ll croot(ll n,ll low=1,ll high=1e6+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid*mid;
    if(a>n)return croot(n,low,mid-1);
    else return croot(n,mid,high);

}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,w;cin>>n>>w;
	ll a[n];fo(i,n)cin>>a[i];
	ll l=0,r=w;

	ll dp[n];
	dp[0]=a[0];
	fo1(i,n-1)
	dp[i]=dp[i-1]+a[i];

	//fo(i,n)cout<<dp[i]<<" ";cout<<endl;
	ll f=0;
	fo(i,n)
	{
		ll x=dp[i];
		if(x!=0)
		{
			if(x>0 && r+x>w)
			r=(r+x-w);
			else if(x<0 && l-abs(x)<0)
			l=(abs(x));
		}
		if(r<0||l>w){
			f=1;break;
		}
		//cout<<l<<" "<<r<<endl;
	}
	if(f==1||(r<l)||(r-l+1)>w || (r-l+1)<0)cout<<"0";
	else
	cout<<(r-l)+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

int ispal(string s){
    int len=s.size();
    int flag=1;
    for(int i=0;i<len;++i){
        if(s[i]!=s[len-i-1]){
            flag=0;break;
        }
    }
    return flag;
}

ll sroot(ll n,ll low=1,ll high=1e9+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid;
    if(a>n)return sroot(n,low,mid-1);
    else return sroot(n,mid,high);
}
ll croot(ll n,ll low=1,ll high=1e6+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid*mid;
    if(a>n)return croot(n,low,mid-1);
    else return croot(n,mid,high);

}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,w;cin>>n>>w;
	ll a[n];fo(i,n)cin>>a[i];
	ll l=0,r=w;

	ll dp[n];
	dp[0]=a[0];
	fo1(i,n-1)
	dp[i]=dp[i-1]+a[i];

	//fo(i,n)cout<<dp[i]<<" ";cout<<endl;
	ll f=0;
	fo(i,n)
	{
		ll x=dp[i];
		if(x!=0)
		{
			if(x>0 && r+x>w)
			r=(w-x);
			else if(x<0 && l-abs(x)<0)
			l=(abs(x));
		}
		if(r<0||l>w){
			f=1;break;
		}
		//cout<<l<<" "<<r<<endl;
	}
	if(f==1||(r<l)||(r-l+1)>w || (r-l+1)<0)cout<<"0";
	else
	cout<<(r-l)+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

int ispal(string s){
    int len=s.size();
    int flag=1;
    for(int i=0;i<len;++i){
        if(s[i]!=s[len-i-1]){
            flag=0;break;
        }
    }
    return flag;
}

ll sroot(ll n,ll low=1,ll high=1e9+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid;
    if(a>n)return sroot(n,low,mid-1);
    else return sroot(n,mid,high);
}
ll croot(ll n,ll low=1,ll high=1e6+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid*mid;
    if(a>n)return croot(n,low,mid-1);
    else return croot(n,mid,high);

}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,w;cin>>n>>w;
	ll a[n];fo(i,n)cin>>a[i];
	ll l=0,r=w;

	ll dp[n];
	dp[0]=a[0];
	fo1(i,n-1)
	dp[i]=dp[i-1]+a[i];

	//fo(i,n)cout<<dp[i]<<" ";cout<<endl;
	fo(i,n)
	{
		ll x=dp[i];
		if(x!=0)
		{
			if(x>0 && r+x>w)
			r=max(0,w-x);
			else if(x<0 && l-abs(x)<0)
			l=min(w,l+abs(x));
		}
		//cout<<l<<" "<<r<<endl;
	}
	cout<<abs(r-l)+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

int ispal(string s){
    int len=s.size();
    int flag=1;
    for(int i=0;i<len;++i){
        if(s[i]!=s[len-i-1]){
            flag=0;break;
        }
    }
    return flag;
}

ll sroot(ll n,ll low=1,ll high=1e9+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid;
    if(a>n)return sroot(n,low,mid-1);
    else return sroot(n,mid,high);
}
ll croot(ll n,ll low=1,ll high=1e6+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid*mid;
    if(a>n)return croot(n,low,mid-1);
    else return croot(n,mid,high);

}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,w;cin>>n>>w;
	ll a[n];fo(i,n)cin>>a[i];
	ll l=0,r=w;

	ll dp[n];
	dp[0]=a[0];
	fo1(i,n-1)
	dp[i]=dp[i-1]+a[i];

	//fo(i,n)cout<<dp[i]<<" ";cout<<endl;
	ll f=0;
	fo(i,n)
	{
		ll x=dp[i];
		if(x!=0)
		{
			if(x>0 && r+x>w)
			r=(w-x);
			else if(x<0 && l-abs(x)<0)
			l=(l+abs(x));
		}
		if(r<0||l>w){
			f=1;break;
		}
		//cout<<l<<" "<<r<<endl;
	}
	if(f==1)cout<<"0";
	else
	cout<<abs(r-l)+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

int ispal(string s){
    int len=s.size();
    int flag=1;
    for(int i=0;i<len;++i){
        if(s[i]!=s[len-i-1]){
            flag=0;break;
        }
    }
    return flag;
}

ll sroot(ll n,ll low=1,ll high=1e9+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid;
    if(a>n)return sroot(n,low,mid-1);
    else return sroot(n,mid,high);
}
ll croot(ll n,ll low=1,ll high=1e6+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid*mid;
    if(a>n)return croot(n,low,mid-1);
    else return croot(n,mid,high);

}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,w;cin>>n>>w;
	ll a[n];fo(i,n)cin>>a[i];
	ll l=0,r=w;

	ll dp[n];
	dp[0]=a[0];
	fo1(i,n-1)
	dp[i]=dp[i-1]+a[i];

	//fo(i,n)cout<<dp[i]<<" ";cout<<endl;
	ll f=0;
	fo(i,n)
	{
		ll x=dp[i];
		if(x!=0)
		{
			if(x>0 && r+x>w)
			r=min(r,(w-x));
			else if(x<0 && l-abs(x)<0)
			l=max(l,(abs(x)));
		}
		if(r<0||l>w){
			f=1;break;
		}
		//cout<<l<<" "<<r<<endl;
	}
	if(f==1||(r<l)||(r-l+1)>w || (r-l+1)<0)cout<<"0";
	else
	cout<<(r-l)+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

int ispal(string s){
    int len=s.size();
    int flag=1;
    for(int i=0;i<len;++i){
        if(s[i]!=s[len-i-1]){
            flag=0;break;
        }
    }
    return flag;
}

ll sroot(ll n,ll low=1,ll high=1e9+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid;
    if(a>n)return sroot(n,low,mid-1);
    else return sroot(n,mid,high);
}
ll croot(ll n,ll low=1,ll high=1e6+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid*mid;
    if(a>n)return croot(n,low,mid-1);
    else return croot(n,mid,high);

}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,w;cin>>n>>w;
	ll a[n];fo(i,n)cin>>a[i];
	ll l=0,r=w;

	ll dp[n];
	dp[0]=a[0];
	fo1(i,n-1)
	dp[i]=dp[i-1]+a[i];

	//fo(i,n)cout<<dp[i]<<" ";cout<<endl;
	ll f=0;
	fo(i,n)
	{
		ll x=dp[i];
		if(x!=0)
		{
			if(x>0 && r+x>w)
			r=min(r,(w-x));
			else if(x<0 && l-abs(x)<0)
			l=max(l,(abs(x)));
		}
		if(r<0||l>w){
			f=1;break;
		}
		//cout<<l<<" "<<r<<endl;
	}

	if(f==1||(r<l))cout<<"0";
	else
	cout<<(r-l)+1;
	return 0;
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],pre[N],a[N];

void go()
{
	cin >> n >> k;
	int ok = 0;

	fo(i,1,n+1)
	{
		cin >> a[i];
		if( i == 1 and a[i] <= 0 ) ok = 1;
		pre[i] = pre[i-1] + a[i];
	}
	int ans = INF;
	fo(i,1,n+1)
	{
		ans = min( ans , k - pre[i] + 1 - ok);
	}

	if( ans > k ) ans = 0;
	ans = min( ans , k );

	cout << ans << endl;

}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],pre[N],a[N];

void go()
{
	cin >> n >> k;

	int mn = 0;
	int mx = 0;

	fo(i,1,n+1)
	{
		cin >> a[i];
		pre[i] = pre[i-1] + a[i];
		mn = min( pre[i] , mn );
		mx = max( pre[i] , mx );
	}

	mx = min( k , k - mx );
	mn = max( 0LL , -mn );

	int ans = max( 0LL , mx - mn + 1 );

	cout << ans << endl;

}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],pre[N],a[N];

void go()
{
	cin >> n >> k;
	int ok = 0;

	fo(i,1,n+1)
	{
		cin >> a[i];
		if( i == 1 and a[i] <= 0 ) ok = 1;
		pre[i] = pre[i-1] + a[i];
	}
	int ans = INF;
	fo(i,1,n+1)
	{
		ans = min( ans , k - pre[i] + 1 - ok);
	}

	ans = min( ans , k );

	cout << ans << endl;

}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	cin >> n >> k;
	int sum = 0;
	int mx = 0;

	fo(i,0,n)
	{
		cin >> a[i];
		if( i != n-1 ) sum += a[i] , mx = max( mx , a[i] );
	}

	int x = a[n-1] + sum;
	int y = k - mx;

	int ans = min( { n , k - x + 1 , y} );

	if( ans <= 0 ) ans = 0;
	cout << ans << endl;

}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	cin >> n >> k;
	int sum = 0;
	int mx = 0;

	fo(i,0,n)
	{
		cin >> a[i];
		if( i != n-1 ) sum += a[i] , mx = max( mx , a[i] );
	}

	int x = a[n-1] + sum;
	int y = k - mx;

	int ans = min( { k , k - x + 1 , y} );

	if( ans <= 0 ) ans = 0;
	cout << ans << endl;

}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}