#define dzy_分治法_NudistBeach1
#ifdef dzy_分治法_NudistBeach1

#include <stdio.h>
#include <math.h>

#define MAXN 100009
#define MAXM 100009

int n,m,k; // n:城市数 m:边数 k:敌城数

// https://codeforces.com/problemset/problem/553/D
// <"dzy_分治法_NudistBeach.in" >"dzy_分治法_NudistBeach.out"
int main()
{
void set_bad(int v);
void add_edge(int u, int v);
void preprocess();
int check(double mid);
void print();

double low,high,mid;
int u,v;
scanf("%d %d %d",&n,&m,&k);

for(int i=1; i<=k; i++)
	{
	scanf("%d",&v);
	set_bad(v);
	}
for(int i=1; i<=m; i++)
	{
	scanf("%d %d",&u,&v);
	if(u==v)
		continue;
	add_edge(u,v);
	add_edge(v,u);
	}

preprocess(); // 统计每个顶点的信息

low=0.0;high=1.0; // 注意!长度最小为1而不是0!
//while(fabs(high-low) > 1e-8)
for(int i=1; i<=100; i++)
	{
	mid = (low+high)/2;
	if(check(mid))
		{
		low = mid;
		}
	else
		{
		high = mid;
		}
	}

print();

return 0;
}

#include <vector>
#include <set>
typedef struct VERTEX
{
std::set<struct VERTEX*> adj;
int index;
int is_bad;
int deg; // 出度
int enemy; // 敌城数
int fri; // 友城数
}VERTEX,*VERTEX_PTR;
VERTEX vert[MAXN];

void set_bad(int v)
{
vert[v].is_bad=1;
}
void add_edge(int u, int v)
{
vert[u].adj.insert(&vert[v]);
}

void preprocess()
{
for(int i=1; i<=n; i++)
	{
	VERTEX_PTR v = &vert[i];
	v->index=i;
	if(!v->is_bad)
		{
		v->deg = v->adj.size();
		for(std::set<VERTEX_PTR>::iterator vptr=v->adj.begin(); vptr!=v->adj.end(); vptr++)
			if((*vptr)->is_bad)
				v->enemy++;
		}
	}
}

#include <queue>
std::set<VERTEX_PTR> g,ans;
std::queue<VERTEX_PTR> q;
int check(double mid) // 检查是否能找到一些城市使它们安全感大于等于mid,用类似bfs的方式
{
double safe_val(VERTEX_PTR v);
void give_up(VERTEX_PTR u);
int found;

g.clear();
for(int i=1; i<=n; i++)
	{
	VERTEX_PTR v = &vert[i];
	if(!v->is_bad)
		{
		v->fri = v->deg - v->enemy;
		g.insert(v);
		}
	}

for(std::set<VERTEX_PTR>::iterator vptr = g.begin(); vptr!=g.end(); vptr++)
	{
	VERTEX_PTR v = (*vptr);
	if(safe_val(v) < mid)
		{
		q.push(v);
		g.erase(v);
		}
	}

while(!q.empty())
	{
	VERTEX_PTR u = q.front();
	q.pop();
	for(std::set<VERTEX_PTR>::iterator vptr = u->adj.begin(); vptr!=u->adj.end(); vptr++)
		{
		VERTEX_PTR v = *vptr;
		if(g.count(v))
			{
			v->fri--;
			if(safe_val(v) < mid)
				{
				q.push(v);
				g.erase(v);
				}
			}
		}
	}
if(g.size() > 0)
	ans=g;
return(g.size() > 0);
}

double safe_val(VERTEX_PTR v)
{
if(v->fri == 0)
	return 1e-8;
else
	return (double)v->fri / (double)v->deg;
}

void print()
{
printf("%d\n",ans.size());
for(std::set<VERTEX_PTR>::iterator vptr = ans.begin(); vptr!=ans.end(); vptr++)
	{
	VERTEX_PTR v = *vptr;
	printf("%d ", v->index);
	}
}

#endif


#define dzy_分治法_NudistBeach
#ifdef dzy_分治法_NudistBeach

#include <stdio.h>

#define MAXN 100009
#define MAXM 100009

int n,m,k; // n:顶点数 m:边数 k:坏点数
int bad[MAXN];
int ans,selected[MAXN];

//
// <"dzy_分治法_NudistBeach.in" >"dzy_分治法_NudistBeach.out"
int main()
{
void add_edge(int u, int v);
int check(double mid ,int *pans, int *pselected);
int LE(double a, double b);

double low,high,mid;
int t,u,v;
scanf("%d %d %d",&n,&m,&k);

for(int i=1; i<=k; i++)
	{
	scanf("%d",&t);
	bad[t]=1;
	}
for(int i=1; i<=m; i++)
	{
	scanf("%d %d",&u,&v);
	if(u==v) // 去掉自环
		continue;
	add_edge(u,v);
	add_edge(v,u);
	}

low=0.0;high=1.0; // 注意!长度最小为1而不是0!
while(LE(low,high))
	{
	mid = (low+high)/2;
	if(check(mid, &ans, selected))
		{
		low = mid;
		}
	else
		{
		high = mid;
		}
	}

printf("%d\n",ans);
for(int i=1; i<=ans; i++)
	printf("%d ", selected[i]);

return 0;
}

typedef struct EDGE
{
int from,to,next;
}EDGE;

EDGE edge[2*MAXM];
int link_e[MAXN], etot;
void add_edge(int u, int v)
{
EDGE e;
e.from = u;
e.to = v;
e.next=link_e[u];
edge[++etot]=e;
link_e[u]=etot;
}

#include <queue>
using std::vector;

int g[MAXN],vtot;
int check(double mid ,int *pans, int *pselected) // 检查是否能删除一些点使活跃度大于等于mid
{
double sec(int u);

int satisfy;
vtot=0;
for(int i=1; i<=n; i++)
	{
	if(!bad[i])
		{
		g[i]=1;
		vtot++;
		}
	else
		{
		g[i]=0;
		}
	}
while(vtot > 0)
	{
	satisfy = 1;
	for(int i=1; i<=n; i++)
		{
		if(g[i] && (sec(i) < mid))
			{
			g[i]=0;
			vtot--;
			satisfy=0;
			}
		}
	if(satisfy)
		{
		*pans = vtot;
		for(int i=1,tot=0; i<=n; i++)
			{
			if(g[i])
				{
				pselected[++tot]=i;
				}
			}
		return(1);
		}
	}
return(0);
}

double sec(int u) // 求一个城市的安全感
{
int vis[MAXN];
int d, adj;
d = adj = 0;
for(int i=link_e[u]; i; i=edge[i].next)
	{
	if(!vis[edge[i].to]) // 去掉重边
		{
		if(g[edge[i].to]) // 如果邻接点在S中...
			{
			d++;
			}

		adj++;
		vis[edge[i].to]=1;
		}
	}
return 1.0*d / 1.0*adj;
}

#include <math.h>
int LE(double a, double b) // less equal
{
return fabs(a-b) > 1e-8;
}

#endif


#define dzy_分治法_NudistBeach
#ifdef dzy_分治法_NudistBeach

#include <stdio.h>

#define MAXN 100009
#define MAXM 100009

int n,m,k; // n:顶点数 m:边数 k:坏点数
int bad[MAXN];
int ans,selected[MAXN];

//
// <"dzy_分治法_NudistBeach.in" >"dzy_分治法_NudistBeach.out"
int main()
{
void add_edge(int u, int v);
int check(double mid ,int *pans, int *pselected);
int LE(double a, double b);

double low,high,mid;
int t,u,v;
scanf("%d %d %d",&n,&m,&k);

for(int i=1; i<=k; i++)
	{
	scanf("%d",&t);
	bad[t]=1;
	}
for(int i=1; i<=m; i++)
	{
	scanf("%d %d",&u,&v);
	add_edge(u,v);
	add_edge(v,u);
	}

low=0.0;high=1.0; // 注意!长度最小为1而不是0!
while(LE(low,high))
	{
	mid = (low+high)/2;
	if(check(mid, &ans, selected))
		{
		low = mid;
		}
	else
		{
		high = mid;
		}
	}

printf("%d\n",ans);
for(int i=1; i<=ans; i++)
	printf("%d ", selected[i]);

return 0;
}

typedef struct EDGE
{
int from,to,next;
}EDGE;

EDGE edge[MAXM];
int link_e[MAXN], etot;
void add_edge(int u, int v)
{
EDGE e;
e.from = u;
e.to = v;
e.next=link_e[u];
edge[++etot]=e;
link_e[u]=etot;
}

#include <queue>
using std::vector;

int g[MAXN],vtot;
int check(double mid ,int *pans, int *pselected) // 检查是否能删除一些点使活跃度大于等于mid
{
double sec(int u);

int satisfy;
vtot=0;
for(int i=1; i<=n; i++)
	{
	if(!bad[i])
		{
		g[i]=1;
		vtot++;
		}
	else
		{
		g[i]=0;
		}
	}
while(vtot > 0)
	{
	satisfy = 1;
	for(int i=1; i<=n; i++)
		{
		if(g[i] && (sec(i) < mid))
			{
			g[i]=0;
			vtot--;
			satisfy=0;
			}
		}
	if(satisfy)
		{
		*pans = vtot;
		for(int i=1,tot=0; i<=n; i++)
			{
			if(g[i])
				{
				pselected[++tot]=i;
				}
			}
		return(1);
		}
	}
return(0);
}

double sec(int u) // 求一个城市的安全感
{
int d, adj;
d = adj = 0;
for(int i=link_e[u]; i; i=edge[i].next)
	{
	if(g[edge[i].to]) // 如果邻接点在S中...
		{
		d++;
		}
	adj++;
	}
return 1.0 * d / adj;
}

#include <math.h>
int LE(double a, double b) // less equal
{
return fabs(a-b) > 1e-8;
}

#endif


#define dzy_分治法_NudistBeach
#ifdef dzy_分治法_NudistBeach

#include <stdio.h>

#define MAXN 100009
#define MAXM 100009

int n,m,k; // n:顶点数 m:边数 k:坏点数
int bad[MAXN];
int ans,selected[MAXN];

//
// <"dzy_分治法_NudistBeach.in" >"dzy_分治法_NudistBeach.out"
int main()
{
void add_edge(int u, int v);
int check(double mid ,int *pans, int *pselected);
int LE(double a, double b);

double low,high,mid;
int t,u,v;
scanf("%d %d %d",&n,&m,&k);

for(int i=1; i<=k; i++)
	{
	scanf("%d",&t);
	bad[t]=1;
	}
for(int i=1; i<=m; i++)
	{
	scanf("%d %d",&u,&v);
	add_edge(u,v);
	add_edge(v,u);
	}

low=0.0;high=1.0; // 注意!长度最小为1而不是0!
while(LE(low,high))
	{
	mid = (low+high)/2;
	if(check(mid, &ans, selected))
		{
		low = mid;
		}
	else
		{
		high = mid;
		}
	}

printf("%d\n",ans);
for(int i=1; i<=ans; i++)
	printf("%d ", selected[i]);

return 0;
}

typedef struct EDGE
{
int from,to,next;
}EDGE;

EDGE edge[2*MAXM];
int link_e[MAXN], etot;
void add_edge(int u, int v)
{
EDGE e;
e.from = u;
e.to = v;
e.next=link_e[u];
edge[++etot]=e;
link_e[u]=etot;
}

#include <queue>
using std::vector;

int g[MAXN],vtot;
int check(double mid ,int *pans, int *pselected) // 检查是否能删除一些点使活跃度大于等于mid
{
double sec(int u);

int satisfy;
vtot=0;
for(int i=1; i<=n; i++)
	{
	if(!bad[i])
		{
		g[i]=1;
		vtot++;
		}
	else
		{
		g[i]=0;
		}
	}
while(vtot > 0)
	{
	satisfy = 1;
	for(int i=1; i<=n; i++)
		{
		if(g[i] && (sec(i) < mid))
			{
			g[i]=0;
			vtot--;
			satisfy=0;
			}
		}
	if(satisfy)
		{
		*pans = vtot;
		for(int i=1,tot=0; i<=n; i++)
			{
			if(g[i])
				{
				pselected[++tot]=i;
				}
			}
		return(1);
		}
	}
return(0);
}

double sec(int u) // 求一个城市的安全感
{
int d, adj;
d = adj = 0;
for(int i=link_e[u]; i; i=edge[i].next)
	{
	if(g[edge[i].to]) // 如果邻接点在S中...
		{
		d++;
		}
	adj++;
	}
return 1.0 * d / adj;
}

#include <math.h>
int LE(double a, double b) // less equal
{
return fabs(a-b) > 1e-8;
}

#endif


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

#define LET(x, a)  __typeof(a) x(a)
#define TR(v, it) for(LET(it, v.begin()); it != v.end(); it++)
#define si(x) scanf("%d",&x)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 1000000000
#define MOD 1000000007
#define SET(x,y) memset(x,y,sizeof(x));
#define LL long long int
#define ULL unsigned LL
#define PII pair<int, int>
int n, k, m;
int fort[100004];
vector<vector<int> > v, vv;
int nbr[100005];
int l_nbr[100005];
int removed[100005];
int inq[100005];
bool pos(LL num, LL den) {
    v = vv;
    int i, j;
    memset(removed, 0, sizeof(removed));
    memset(inq, 0, sizeof(inq));
    for (i = 0; i < n; i++) {
        nbr[i] = v[i].size();
    }
    for (i = 0; i < n; i++) {
        l_nbr[i] = (num * nbr[i] + y - 1) / y;
    }

    queue<int> rem;
    for (i = 0; i < k; i++) {
        rem.push(fort[i]);
        inq[fort[i]] = 1;
    }
    int sz = n;
    while (!rem.empty()) {
        int cn = rem.front();
        rem.pop();
        removed[cn] = 1;
        sz --;
        for (int j = 0; j < (int)v[cn].size(); j++) {
            int nb = v[cn][j];
            if (removed[nb])
                continue;
            nbr[nb]--;
            if (nbr[nb] < l_nbr[nb] && !inq[nb]) {
                rem.push(nb);
                inq[nb] = 1;
            }
        }
    }
    return sz > 0;
}
vector<PII> poss;
bool cmp(PII a, PII b) {
    return a.first * (LL)b.second < a.second * (LL)b.first
}
int main() {
    int i, j, x, y;
    cin >> n >> m >> k;
    for (i = 0; i < k; i++) {
        cin >> fort[i];
        fort[i] --;
    }
    vv.resize(n);
    while (m--) {
        scanf("%d %d", &x, &y);
        x--;
        y--;
        vv[x].PB(y);
        vv[y].PB(x);
    }
    for (i = 0; i < n; i++) {
        for (j = 1; j <= (int)v[i].size(); j++) {
            poss.PB(MP(j, v[i].size()));
        }
    }
    sort(poss.begin(), poss.end());
    double lb = 0, ub = (int)poss.size(), mid;
    while (tries--) {
        mid = (lb + ub) / 2;
        if (pos(poss.first, poss.second)) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    cerr << mid << endl;
    vector<int> ans;
    for (i = 0; i < n; i++) {
        if (removed[i] == 0) {
            ans.PB(i + 1);
        }
    }
    cout << ans.size() << endl;
    for (i = 0; i < (int)ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


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

#define LET(x, a)  __typeof(a) x(a)
#define TR(v, it) for(LET(it, v.begin()); it != v.end(); it++)
#define si(x) scanf("%d",&x)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 1000000000
#define MOD 1000000007
#define SET(x,y) memset(x,y,sizeof(x));
#define LL long long int
#define ULL unsigned LL
#define PII pair<int, int>
int n, k, m;
int fort[100004];
vector<vector<int> > v, vv;
int nbr[100005];
int l_nbr[100005];
int removed[100005];
int inq[100005];
bool pos(LL num, LL den) {
    v = vv;
    int i, j;
    memset(removed, 0, sizeof(removed));
    memset(inq, 0, sizeof(inq));
    for (i = 0; i < n; i++) {
        nbr[i] = v[i].size();
    }
    for (i = 0; i < n; i++) {
        l_nbr[i] = (num * nbr[i] + den - 1) / den;
    }

    queue<int> rem;
    for (i = 0; i < k; i++) {
        rem.push(fort[i]);
        inq[fort[i]] = 1;
    }
    int sz = n;
    while (!rem.empty()) {
        int cn = rem.front();
        rem.pop();
        removed[cn] = 1;
        sz --;
        for (int j = 0; j < (int)v[cn].size(); j++) {
            int nb = v[cn][j];
            if (removed[nb])
                continue;
            nbr[nb]--;
            if (nbr[nb] < l_nbr[nb] && !inq[nb]) {
                rem.push(nb);
                inq[nb] = 1;
            }
        }
    }
    return sz > 0;
}
vector<PII> poss;
bool cmp(PII a, PII b) {
    return a.first * (LL)b.second < a.second * (LL)b.first;
}
map<PII, int> done;
void add(int x, int y) {
    int g = __gcd(x, y);
    x /= g;
    y /= g;
    if (done.count(MP(x, y)))
        return;
    done[MP(x, y)];
    poss.PB(MP(x, y));
}
int main() {
    int i, j, x, y;
    cin >> n >> m >> k;
    for (i = 0; i < k; i++) {
        cin >> fort[i];
        fort[i] --;
    }
    vv.resize(n);
    while (m--) {
        scanf("%d %d", &x, &y);
        x--;
        y--;
        vv[x].PB(y);
        vv[y].PB(x);
    }
    for (i = 0; i < n; i++) {
        for (j = 1; j <= (int)vv[i].size(); j++) {
            add(j, vv[i].size());
        }
    }
    sort(poss.begin(), poss.end(), cmp);
    int lb = 0, ub = (int)poss.size() - 1, mid, ans2 = -1;
    while (lb <= ub) {
        mid = (lb + ub) / 2;
        if (pos(poss[mid].first, poss[mid].second)) {
            lb = mid + 1;
            ans2 = mid;
        } else {
            ub = mid - 1;
        }
    }
    mid = ans2;
    pos(poss[mid].first, poss[mid].second);
    cerr << poss[mid].first << "/" << poss[mid].second << endl;
    vector<int> ans;
    for (i = 0; i < n; i++) {
        if (removed[i] == 0) {
            ans.PB(i + 1);
        }
    }
    cout << ans.size() << endl;
    for (i = 0; i < (int)ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


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

#define LET(x, a)  __typeof(a) x(a)
#define TR(v, it) for(LET(it, v.begin()); it != v.end(); it++)
#define si(x) scanf("%d",&x)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 1000000000
#define MOD 1000000007
#define SET(x,y) memset(x,y,sizeof(x));
#define LL long long int
#define ULL unsigned LL
#define PII pair<int, int>
int n, k, m;
int fort[100004];
vector<vector<int> > v, vv;
int nbr[100005];
int l_nbr[100005];
int removed[100005];
int inq[100005];
bool pos(LL num, LL den) {
    v = vv;
    int i, j;
    memset(removed, 0, sizeof(removed));
    memset(inq, 0, sizeof(inq));
    for (i = 0; i < n; i++) {
        nbr[i] = v[i].size();
    }
    for (i = 0; i < n; i++) {
        l_nbr[i] = (num * nbr[i] + den - 1) / den;
    }

    queue<int> rem;
    for (i = 0; i < k; i++) {
        rem.push(fort[i]);
        inq[fort[i]] = 1;
    }
    int sz = n;
    while (!rem.empty()) {
        int cn = rem.front();
        rem.pop();
        removed[cn] = 1;
        sz --;
        for (int j = 0; j < (int)v[cn].size(); j++) {
            int nb = v[cn][j];
            if (removed[nb])
                continue;
            nbr[nb]--;
            if (nbr[nb] < l_nbr[nb] && !inq[nb]) {
                rem.push(nb);
                inq[nb] = 1;
            }
        }
    }
    return sz > 0;
}
vector<PII> poss;
bool cmp(PII a, PII b) {
    return a.first * (LL)b.second < a.second * (LL)b.first;
}
int main() {
    int i, j, x, y;
    cin >> n >> m >> k;
    for (i = 0; i < k; i++) {
        cin >> fort[i];
        fort[i] --;
    }
    vv.resize(n);
    while (m--) {
        scanf("%d %d", &x, &y);
        x--;
        y--;
        vv[x].PB(y);
        vv[y].PB(x);
    }
    for (i = 0; i < n; i++) {
        for (j = 1; j <= (int)v[i].size(); j++) {
            poss.PB(MP(j, v[i].size()));
        }
    }
    sort(poss.begin(), poss.end());
    double lb = 0, ub = (int)poss.size(), mid;
    while (lb <= ub) {
        mid = (lb + ub) / 2;
        if (pos(poss[mid].first, poss[mid].second)) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    cerr << mid << endl;
    vector<int> ans;
    for (i = 0; i < n; i++) {
        if (removed[i] == 0) {
            ans.PB(i + 1);
        }
    }
    cout << ans.size() << endl;
    for (i = 0; i < (int)ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


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

#define LET(x, a)  __typeof(a) x(a)
#define TR(v, it) for(LET(it, v.begin()); it != v.end(); it++)
#define si(x) scanf("%d",&x)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 1000000000
#define MOD 1000000007
#define SET(x,y) memset(x,y,sizeof(x));
#define LL long long int
#define ULL unsigned LL
#define PII pair<int, int>
int n, k, m;
int fort[100004];
vector<vector<int> > v, vv;
int nbr[100005];
int l_nbr[100005];
int removed[100005];
int inq[100005];
bool pos(double mid) {
    v = vv;
    int i, j;
    memset(removed, 0, sizeof(removed));
    memset(inq, 0, sizeof(inq));
    for (i = 0; i < n; i++) {
        nbr[i] = v[i].size();
    }
    for (i = 0; i < n; i++) {
        l_nbr[i] = ceil(mid * nbr[i] - 1e-10);
    }

    queue<int> rem;
    for (i = 0; i < k; i++) {
        rem.push(fort[i]);
        inq[fort[i]] = 1;
    }
    int sz = n;
    while (!rem.empty()) {
        int cn = rem.front();
        rem.pop();
        removed[cn] = 1;
        sz --;
        for (int j = 0; j < (int)v[cn].size(); j++) {
            int nb = v[cn][j];
            if (removed[nb])
                continue;
            nbr[nb]--;
            if (nbr[nb] < l_nbr[nb] && !inq[nb]) {
                rem.push(nb);
                inq[nb] = 1;
            }
        }
    }
    return sz > 0;
}
int main() {
    int i, j, x, y;
    cin >> n >> m >> k;
    for (i = 0; i < k; i++) {
        cin >> fort[i];
        fort[i] --;
    }
    vv.resize(n);
    while (m--) {
        scanf("%d %d", &x, &y);
        x--;
        y--;
        vv[x].PB(y);
        vv[y].PB(x);
    }
    double lb = 0, ub = 1, mid;
    int tries = 50;
    while (tries--) {
        mid = (lb + ub) / 2;
        if (pos(mid)) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    cerr << mid << endl;
    vector<int> ans;
    for (i = 0; i < n; i++) {
        if (removed[i] == 0) {
            ans.PB(i + 1);
        }
    }
    cout << ans.size() << endl;
    for (i = 0; i < (int)ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


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

#define LET(x, a)  __typeof(a) x(a)
#define TR(v, it) for(LET(it, v.begin()); it != v.end(); it++)
#define si(x) scanf("%d",&x)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 1000000000
#define MOD 1000000007
#define SET(x,y) memset(x,y,sizeof(x));
#define LL long long int
#define ULL unsigned LL
#define PII pair<int, int>
int n, k, m;
int fort[100004];
vector<vector<int> > v, vv;
int nbr[100005];
int l_nbr[100005];
int removed[100005];
int inq[100005];
bool pos(LL num, LL den) {
    v = vv;
    int i, j;
    memset(removed, 0, sizeof(removed));
    memset(inq, 0, sizeof(inq));
    for (i = 0; i < n; i++) {
        nbr[i] = v[i].size();
    }
    for (i = 0; i < n; i++) {
        l_nbr[i] = (num * nbr[i] + den - 1) / den;
    }

    queue<int> rem;
    for (i = 0; i < k; i++) {
        rem.push(fort[i]);
        inq[fort[i]] = 1;
    }
    int sz = n;
    while (!rem.empty()) {
        int cn = rem.front();
        rem.pop();
        removed[cn] = 1;
        sz --;
        for (int j = 0; j < (int)v[cn].size(); j++) {
            int nb = v[cn][j];
            if (removed[nb])
                continue;
            nbr[nb]--;
            if (nbr[nb] < l_nbr[nb] && !inq[nb]) {
                rem.push(nb);
                inq[nb] = 1;
            }
        }
    }
    return sz > 0;
}
vector<PII> poss;
bool cmp(PII a, PII b) {
    return a.first * (LL)b.second < a.second * (LL)b.first;
}
map<PII, int> done;
void add(int x, int y) {
    int g = __gcd(x, y);
    x /= g;
    y /= g;
    if (done.count(MP(x, y)))
        return;
    done[MP(x, y)];
    poss.PB(MP(x, y));
}
int main() {
    int i, j, x, y;
    cin >> n >> m >> k;
    for (i = 0; i < k; i++) {
        cin >> fort[i];
        fort[i] --;
    }
    vv.resize(n);
    while (m--) {
        scanf("%d %d", &x, &y);
        x--;
        y--;
        vv[x].PB(y);
        vv[y].PB(x);
    }
    for (i = 0; i < n; i++) {
        for (j = 1; j <= (int)vv[i].size(); j++) {
            add(j, vv[i].size());
        }
    }
    poss.PB(MP(0, 1));
    sort(poss.begin(), poss.end(), cmp);
    int lb = 0, ub = (int)poss.size() - 1, mid, ans2 = -1;
    while (lb <= ub) {
        mid = (lb + ub) / 2;
        if (pos(poss[mid].first, poss[mid].second)) {
            lb = mid + 1;
            ans2 = mid;
        } else {
            ub = mid - 1;
        }
    }
    mid = ans2;
    pos(poss[mid].first, poss[mid].second);
    cerr << poss[mid].first << "/" << poss[mid].second << endl;
    vector<int> ans;
    for (i = 0; i < n; i++) {
        if (removed[i] == 0) {
            ans.PB(i + 1);
        }
    }
    cout << ans.size() << endl;
    for (i = 0; i < (int)ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100100;

int n, m, k;
vector <int> a[N], ans;
double p[N];
int dd[N], f[N];
int st[N], top, bot;

int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int u;
    cin >> u;
    f[u] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  double l = 0, r = 1;
  for (int x = 1; x <= 100; x++) {
    double m = (l + r) * 0.5;
    top = bot = 0;
    if (ans.size() == 0) {
      for (int i = 1; i <= n; i++) {
        if (!f[i]) {
          ans.push_back(i);
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (f[i]) {
        st[top++] = i;
        dd[i] = 1;
        p[i] = -1;
      } else {
        p[i] = 1;
        dd[i] = 0;
      }
    }
    while (bot < top) {
      int u = st[bot++];
      for (int i = 0; i < a[u].size(); i++) {
        int v = a[u][i];
        p[v] -= 1.0 / a[v].size();
        if (!dd[v] && p[v] < m) {
          st[top++] = v;
          dd[v] = 1;
        }
      }
    }
    if (top == n) {
      r = m;
    } else {
      l = m;
      ans.clear();
      for (int i = 1; i <= n; i++) {
        if (!dd[i]) {
          ans.push_back(i);
        }
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100100;

int n, m, k, cnt[N];
int f[N], dd[N];
long double p[N];
vector <int> a[N];

bool check(long double lim, bool flag) {
  priority_queue <pair<long double, int> > q;
  for (int i = 1; i <= n; i++) {
    if (f[i]) {
      q.push(make_pair(0, i));
      p[i] = 0;
    } else {
      cnt[i] = a[i].size();
      q.push(make_pair(-1, i));
      p[i] = 1;
    }
    dd[i] = 0;
  }
  while (!q.empty()) {
    int u = q.top().second;
    long double x = p[u];
    q.pop();
    if (x >= lim) {
      if (flag) {
        vector <int> ans;
        for (int i = 1; i <= n; i++) {
          if (!dd[i]) {
            ans.push_back(i);
          }
        }
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); i++) {
          cout << ans[i] << " ";
        }
      }
      return 1;
    }
    if (dd[u]) {
      continue;
    }
    dd[u] = 1;
    for (int i = 0; i < a[u].size(); i++) {
      int v = a[u][i];
      if (!dd[v]) {
        cnt[v]--;
        p[v] = (long double)cnt[v] / a[v].size();
        q.push(make_pair(-p[v], v));
      }
    }
  }
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int u;
    cin >> u;
    f[u] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  long double l = 0, r = 1;
  for (int i = 1; i <= 100; i++) {
    long double m = (l + r) * 0.5;
    if (check(m, 0)) {
      l = m;
    } else {
      r = m;
    }
  }
  check((l + r) * 0.5, 1);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100100;

int n, m, k, cnt[N];
int f[N], dd[N];
long double p[N];
vector <int> a[N];

bool check(long double lim, bool flag) {
  priority_queue <pair<long double, int> > q;
  for (int i = 1; i <= n; i++) {
    if (f[i]) {
      q.push(make_pair(1, i));
      p[i] = -1;
    } else {
      cnt[i] = a[i].size();
      q.push(make_pair(-1, i));
      p[i] = 1;
    }
    dd[i] = 0;
  }
  while (!q.empty()) {
    int u = q.top().second;
    long double x = p[u];
    q.pop();
    if (x + 0.000001 >= lim) {
      if (flag) {
        vector <int> ans;
        for (int i = 1; i <= n; i++) {
          if (!dd[i]) {
            ans.push_back(i);
          }
        }
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); i++) {
          cout << ans[i] << " ";
        }
      }
      return 1;
    }
    if (dd[u]) {
      continue;
    }
    dd[u] = 1;
    for (int i = 0; i < a[u].size(); i++) {
      int v = a[u][i];
      if (!dd[v]) {
        cnt[v]--;
        p[v] = (long double)cnt[v] / a[v].size();
        q.push(make_pair(-p[v], v));
      }
    }
  }
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int u;
    cin >> u;
    f[u] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  long double l = 0, r = 1;
  for (int i = 1; i <= 100; i++) {
    long double m = (l + r) * 0.5;
    if (check(m, 0)) {
      l = m;
    } else {
      r = m;
    }
  }
  check((l + r) * 0.5, 1);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100100;

int n, m, k, cnt[N];
int f[N], dd[N];
long double p[N];
vector <int> a[N];

bool check(long double lim, bool flag) {
  priority_queue <pair<long double, int> > q;
  for (int i = 1; i <= n; i++) {
    if (f[i]) {
      q.push(make_pair(1, i));
      p[i] = -1;
    } else {
      cnt[i] = a[i].size();
      q.push(make_pair(-1, i));
      p[i] = 1;
    }
    dd[i] = 0;
  }
  while (!q.empty()) {
    int u = q.top().second;
    long double x = p[u];
    q.pop();
    if (x + 0.000001 >= lim) {
      if (flag) {
        vector <int> ans;
        for (int i = 1; i <= n; i++) {
          if (!dd[i]) {
            ans.push_back(i);
          }
        }
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); i++) {
          cout << ans[i] << " ";
        }
      }
      return 1;
    }
    if (dd[u]) {
      continue;
    }
    dd[u] = 1;
    for (int i = 0; i < a[u].size(); i++) {
      int v = a[u][i];
      if (!dd[v]) {
        cnt[v]--;
        p[v] = (long double)cnt[v] / a[v].size();
        q.push(make_pair(-p[v], v));
      }
    }
  }
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int u;
    cin >> u;
    f[u] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  long double l = 0, r = 1.1;
  for (int i = 1; i <= 100; i++) {
    long double m = (l + r) * 0.5;
    if (check(m, 0)) {
      l = m;
    } else {
      r = m;
    }
  }
  check(l, 1);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100100;

int n, m, k, cnt[N];
int f[N], dd[N];
long double p[N];
vector <int> a[N];

bool check(long double lim, bool flag) {
  priority_queue <pair<long double, int> > q;
  for (int i = 1; i <= n; i++) {
    if (f[i]) {
      q.push(make_pair(1, i));
      p[i] = -1;
    } else {
      cnt[i] = a[i].size();
      q.push(make_pair(-1, i));
      p[i] = 1;
    }
    dd[i] = 0;
  }
  while (!q.empty()) {
    int u = q.top().second;
    long double x = p[u];
    q.pop();
    if (x + 0.000001 >= lim) {
      if (flag) {
        vector <int> ans;
        for (int i = 1; i <= n; i++) {
          if (!dd[i]) {
            ans.push_back(i);
          }
        }
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); i++) {
          cout << ans[i] << " ";
        }
      }
      return 1;
    }
    if (dd[u]) {
      continue;
    }
    dd[u] = 1;
    for (int i = 0; i < a[u].size(); i++) {
      int v = a[u][i];
      if (!dd[v]) {
        cnt[v]--;
        p[v] = (long double)cnt[v] / a[v].size();
        q.push(make_pair(-p[v], v));
      }
    }
  }
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int u;
    cin >> u;
    f[u] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  long double l = 0, r = 1.1;
  for (int i = 1; i <= 50; i++) {
    long double m = (l + r) * 0.5;
    if (check(m, 0)) {
      l = m;
    } else {
      r = m;
    }
  }
  check(l, 1);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100100;

int n, m, k, cnt[N];
int f[N], dd[N];
long double p[N];
vector <int> a[N];

bool check(long double lim, bool flag) {
  priority_queue <pair<long double, int> > q;
  for (int i = 1; i <= n; i++) {
    if (f[i]) {
      q.push(make_pair(0, i));
      p[i] = 0;
    } else {
      cnt[i] = a[i].size();
      q.push(make_pair(-1, i));
      p[i] = 1;
    }
    dd[i] = 0;
  }
  while (!q.empty()) {
    int u = q.top().second;
    long double x = p[u];
    q.pop();
    if (dd[u]) {
      continue;
    }
    if (x >= lim) {
      if (flag) {
        vector <int> ans;
        for (int i = 1; i <= n; i++) {
          if (!dd[i]) {
            ans.push_back(i);
          }
        }
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); i++) {
          cout << ans[i] << " ";
        }
      }
      return 1;
    }
    dd[u] = 1;
    for (int i = 0; i < a[u].size(); i++) {
      int v = a[u][i];
      if (!dd[v]) {
        cnt[v]--;
        p[v] = (long double)cnt[v] / a[v].size();
        q.push(make_pair(-p[v], v));
      }
    }
  }
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int u;
    cin >> u;
    f[u] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  long double l = 0, r = 1;
  for (int i = 1; i <= 100; i++) {
    long double m = (l + r) * 0.5;
    if (check(m, 0)) {
      l = m;
    } else {
      r = m;
    }
  }
  check((l + r) * 0.5, 1);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100100;

int n, m, k, cnt[N];
int f[N], dd[N];
long double p[N];
vector <int> a[N];

bool check(long double lim, bool flag) {
  priority_queue <pair<long double, int> > q;
  for (int i = 1; i <= n; i++) {
    if (f[i]) {
      q.push(make_pair(1, i));
      p[i] = -1;
    } else {
      cnt[i] = a[i].size();
      q.push(make_pair(-1, i));
      p[i] = 1;
    }
    dd[i] = 0;
  }
  while (!q.empty()) {
    int u = q.top().second;
    long double x = p[u];
    q.pop();
    if (x + 0.000001 >= lim) {
      if (flag) {
        vector <int> ans;
        for (int i = 1; i <= n; i++) {
          if (!dd[i]) {
            ans.push_back(i);
          }
        }
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); i++) {
          cout << ans[i] << " ";
        }
      }
      return 1;
    }
    if (dd[u]) {
      continue;
    }
    dd[u] = 1;
    for (int i = 0; i < a[u].size(); i++) {
      int v = a[u][i];
      if (!dd[v]) {
        cnt[v]--;
        p[v] = (long double)cnt[v] / a[v].size();
        q.push(make_pair(-p[v], v));
      }
    }
  }
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int u;
    cin >> u;
    f[u] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  long double l = 0, r = 1. 1;
  for (int i = 1; i <= 100; i++) {
    long double m = (l + r) * 0.5;
    if (check(m, 0)) {
      l = m;
    } else {
      r = m;
    }
  }
  check(l * 0.5, 1);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100100;

int n, m, k, cnt[N];
int f[N], dd[N];
long double p[N];
vector <int> a[N];

bool check(long double lim, bool flag) {
  priority_queue <pair<long double, int> > q;
  for (int i = 1; i <= n; i++) {
    if (f[i]) {
      q.push(make_pair(1, i));
      p[i] = -1;
    } else {
      cnt[i] = a[i].size();
      q.push(make_pair(-1, i));
      p[i] = 1;
    }
    dd[i] = 0;
  }
  while (!q.empty()) {
    int u = q.top().second;
    long double x = p[u];
    q.pop();
    if (x + 0.000001 >= lim) {
      if (flag) {
        vector <int> ans;
        for (int i = 1; i <= n; i++) {
          if (!dd[i]) {
            ans.push_back(i);
          }
        }
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); i++) {
          cout << ans[i] << " ";
        }
      }
      return 1;
    }
    if (dd[u]) {
      continue;
    }
    dd[u] = 1;
    for (int i = 0; i < a[u].size(); i++) {
      int v = a[u][i];
      if (!dd[v]) {
        cnt[v]--;
        p[v] = (long double)cnt[v] / a[v].size();
        q.push(make_pair(-p[v], v));
      }
    }
  }
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int u;
    cin >> u;
    f[u] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  long double l = 0, r = 1.1;
  for (int i = 1; i <= 100; i++) {
    long double m = (l + r) * 0.5;
    if (check(m, 0)) {
      l = m;
    } else {
      r = m;
    }
  }
  check(l * 0.5, 1);
  return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cstring>

using namespace std;

typedef long long ll;

const int MAXN = 1005;
const int  MOD = 1000000007;
const double EPS = 1e-9;

vector<int> g[MAXN];
int tot[MAXN], good[MAXN];
int p[MAXN], q[MAXN];
set<int> bad;
bool vis[MAXN];
vector<int> res;

int main()
{
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);

    for (int i = 0; i < k; ++ i) {
        int val;
        scanf("%d", &val);
        -- val;
        bad.insert(val);
    }

    for (int i = 0; i < m; ++ i) {
        int a, b;
        scanf("%d%d", &a, &b);
        -- a, -- b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for (int i = 0; i < n; ++ i) {
        good[i] = tot[i] = (int)g[i].size();
    }

    for (int u : bad) {
        for (int v : g[u]) {
            -- good[v];
        }
    }

    double low = 0, high = 1;

    for (int i = 0; i < 100; ++ i) {
        double mid = 0.5 * (low + high);
        queue<int> Q;

        for (int j = 0; j < n; ++ j) {
            p[j] = tot[j];
            q[j] = good[j];
            vis[j] = false;
        }

        for (int j = 0; j < n; ++ j) {
            if (!bad.count(j)) {
                if (1.0 * q[j] <= mid * p[j] - EPS) {
                    Q.push(j);
                }
            }
        }

        int cur = n - k;

        while (!Q.empty()) {
            -- cur;
            int u = Q.front(); Q.pop();
            vis[u] = true;

            for (int v : g[u]) {
                if (!bad.count(v)) {
                    -- q[v];
                    double val = 1.0 * q[v] / p[v];
                    if ((val <= mid - EPS) && !vis[v]) {
                        Q.push(v);
                        //printf("%d %d %d\n", q[v], p[v], v);
                    }
                }
            }
        }

        if (cur > 0) {
            low = mid;
            res.clear();
            for (int j = 0; j < n; ++ j) {
                if (!vis[j] && !bad.count(j)) {
                    res.push_back(j);
                }
            }
        } else {
            high = mid;
        }
    }

    printf("%d\n", (int)res.size());

    for (int i = 0; i + 1 < (int)res.size(); ++ i) {
        printf("%d ", res[i] + 1);
    }

    printf("%d\n", res.back() + 1);
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cstring>

using namespace std;

typedef long long ll;

const int MAXN = 100005;
const int  MOD = 1000000007;
const double EPS = 1e-9;

vector<int> g[MAXN];
int tot[MAXN], good[MAXN];
int p[MAXN], q[MAXN];
set<int> bad;
bool vis[MAXN];
vector<int> res;

int main()
{
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);

    for (int i = 0; i < k; ++ i) {
        int val;
        scanf("%d", &val);
        -- val;
        bad.insert(val);
    }

    for (int i = 0; i < m; ++ i) {
        int a, b;
        scanf("%d%d", &a, &b);
        -- a, -- b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for (int i = 0; i < n; ++ i) {
        good[i] = tot[i] = (int)g[i].size();
    }

    for (int u : bad) {
        for (int v : g[u]) {
            -- good[v];
        }
    }

    double low = 0, high = 1;

    for (int i = 0; i < 50; ++ i) {
        double mid = 0.5 * (low + high);
        queue<int> Q;

        for (int j = 0; j < n; ++ j) {
            p[j] = tot[j];
            q[j] = good[j];
            vis[j] = false;
        }

        for (int j = 0; j < n; ++ j) {
            if (!bad.count(j)) {
                double val = 1.0 * q[j] / p[j];
                if (val <= mid - EPS) {
                    Q.push(j);
                    vis[j] = true;
                }
            }
        }

        int cur = n - k;

        while (!Q.empty()) {
            -- cur;
            int u = Q.front(); Q.pop();

            for (int v : g[u]) {
                if (!bad.count(v)) {
                    -- q[v];
                    double val = 1.0 * q[v] / p[v];
                    if ((val <= mid - EPS) && !vis[v]) {
                        Q.push(v);
                        vis[v] = true;
                        //printf("%d %d %d\n", q[v], p[v], v);
                    }
                }
            }
        }

        if (cur > 0) {
            low = mid;
            res.clear();
            for (int j = 0; j < n; ++ j) {
                if (!vis[j] && !bad.count(j)) {
                    res.push_back(j);
                }
            }
        } else {
            high = mid;
        }
    }

    printf("%d\n", (int)res.size());

    for (int i = 0; i + 1 < (int)res.size(); ++ i) {
        printf("%d ", res[i] + 1);
    }

    printf("%d\n", res.back() + 1);
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
long long n,m,x,ans,p,flag,a[1000];

int main()
{
    scanf("%I64d%I64d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&a[i]);
        if(a[i]<0&&!flag)
            p+=a[i];
        else
            flag=1;
        x+=a[i];
        ans=max(x,ans);
    }
    if(0-p>m)
    {
        puts("0");
    }
    else
    {
        if(m-ans>=0)
            printf("%d\n",min(m-ans+1,m+p+1));
        else
            puts("0");
    }
    return 0;
}
//2019-07-21 19:51:18.122


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int a[maxn];
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    int ans=m+1,num=0;
    for(int i=1;i<=n;i++) {
        scanf("%d",a+i);
        if(a[i]>=0) {
            if(num<0) {
                if(num+a[i]>0)
                    ans-=num+a[i];
            }
            else
                ans-=a[i];
            num+=a[i];
        }
        else {
            if(num<0)
                ans+=a[i];
            else {
                if(num+a[i]<0)
                    ans+=a[i]+num;
            }
            num+=a[i];
        }
    }
    printf("%d\n",ans>0?ans:0);
    return 0;
}
//2019-07-21 19:59:21.766


#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
long long w;
long long str[1005];
long long sum[1005];
int main()
{
    scanf("%d%I64d",&n,&w);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&str[i]);
    }
    long long ans1=str[1];
    long long ans2=str[1];
    for(int i=1; i<=n; i++)
    {
        sum[i]=sum[i-1]+str[i];
        ans1=min(ans1,sum[i]);
        ans2=max(ans2,sum[i]);
    }
    long long x,y;
    x=max(-ans1,-ans2);
    y=min(w-ans1,w-ans2);
    if(x>y)
        puts("0");
    else if(y<0)
        puts("0");
    else if(x>m)
        puts("0");
    else
    {
        x=(x<0?0:x);
        y=(y>=w?w:y);
        printf("%I64d\n",y-x+1);
    }
    return 0;
}
//2019-07-21 20:45:27.505


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll w;
ll str[1005];
ll sum[1005];
int main()
{
    cin>>n>>w;
    for(int i=1; i<=n; i++)

        scanf("%I64d",&str[i]);

    ll ans1=str[1];
    ll ans2=str[1];
    for(int i=1; i<=n; i++)
    {
        sum[i]=sum[i-1]+str[i];
        ans1=min(ans1,sum[i]);
        ans2=max(ans2,sum[i]);
    }
    ll x,y;
    x=max(-ans1,-ans2);
    y=min(w-ans1,w-ans2);
    if(x>y)
        puts("0");
    else if(y<0)
        puts("0");
    else if(x>w)
        puts("0");
    else
    {
        x=(x<0?0:x);
        y=(y>=w?w:y);
       cout<<y-x-1<<endl;
    }
    return 0;
}
//2019-07-21 22:11:14.087


#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int INF = 0x3F3F3F3F;
const int N = 1005;

int a[N];

int main() {
    ios::sync_with_stdio(false);
    int n, w;
    cin >> n >> w;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) a[i] += a[i - 1];
    int Max = *max_element(a + 1, a + n + 1);
    int Min = *min_element(a + 1, a + n + 1);
    // if Max > 0, 一开始至多有 w - Max 人
    // if Min < 0, 一开始至少有 -Min 人
    int left, right;
    if (Min < 0) {
        left = -Min;
    } else {
        left = 0;
    }
    if (Max > 0) {
        right = w - Max;
    } else {
        right = w;
    }
    if (right < 0) {
        cout << "0\n";
    } else {
        cout << max(0, right - left + 1) << endl;
    }
    return 0;
}//2019-07-21 20:05:57.61


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
const int MAX=1e3+5;
long long record[MAX];
int main()
{
  int n;
  long long w;
  cin >> n >> w;
  long long mi=0, ma=0;
  for (int i=1; i<=n; i++)
  {
    scanf("%I64d", &record[i]);
    record[i] += record[i-1];
    mi = min(record[i], mi);
    ma = max(record[i], ma);
  }
  if (w+mi<0) cout << 0 << endl;
  else if (w<ma) cout << 0 << endl;
  else if (ma-mi>w) cout << 0 << endl;
  else if (mi>=0) cout << w-ma+1 << endl;
  else if (ma<=0) cout << w+mi+1 << endl;
  else cout << abs(w-ma+mi)+1 << endl;

  return 0;
}
//2019-07-21 20:59:41.374


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
long long n,m,x,ans,p=1000000000,q=10000000000,flag,a[1000];

int main()
{
    scanf("%I64d%I64d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&a[i]);
        x+=a[i];
        ans=max(x,ans);
        p=min(x,p);
        if(0-p>m)
            flag=1;
        if(a[i]>0)
            q=min(m-a[i],q);
        if(a[i]>m)
            flag=1;
    }
    if(flag)
        puts("0");
    else
    {
        if(p<0)
        {
            if(m-ans>=0)
                printf("%I64d\n",min(m-ans+1,min(m+p+1,q+1)));
            else
                puts("0");
        }
        else
        {
            if(m-ans>=0)
                printf("%I64d\n",min(m-ans+1,q+1));
            else
                puts("0");
        }
    }
    return 0;
}
//2019-07-21 20:26:59.976


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1005],sum[1005];
double x[1005],y[1005];
int main()
{

    int n,m;
    cin>>n>>m;
    sum[0]=0;
    for(int i=1; i<=n; i++)
        cin>>a[i],sum[i]=sum[i-1]+a[i];

    int f=0;
    for(int i=1; i<=n; i++)
    {
        if(sum[i]>m)
        {
            f=1;
            break;
        }
        else if(sum[i]+m<0)
        {
            f=1;
            break;
        }
    }
    if(f)
    {
        puts("-1");
        return 0;
    }
    ll mi=1;
    int j=1;
    for(int i=1;i<=n;i++)
    {
      if(sum[i]<0)  mi=min(mi,sum[i]);
      else
      x[j++]=m-sum[i];
    }
    sort(x+1,x+j);
    if(mi==1) mi=0;
    ll ans=x[1]+mi+1;

    if(ans<0)
        puts("-1");
    else cout<<ans<<endl;

    return 0;

}
//2019-07-21 20:25:36.491


#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int INF = 0x3F3F3F3F;
const int N = 1005;

int a[N];

int main() {
    ios::sync_with_stdio(false);
    int n, w;
    cin >> n >> w;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) a[i] += a[i - 1];
    int Max = *max_element(a + 1, a + n + 1);
    int Min = *min_element(a + 1, a + n + 1);
    // if Max > 0, 一开始至多有 w - Max 人
    // if Min < 0, 一开始至少有 -Min 人
    int left, right;
    if (Min < 0) {
        left = -Min;
    } else {
        left = 0;
    }
    if (Max > 0) {
        right = w - Max;
    } else {
        right = w;
    }
    if (right < 0) {
        cout << "0\n";
    } else {
        cout << max(0, right - left + 1) << endl;
    }
    return 0;
}//2019-07-21 20:57:19.741


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
long long n,m,x,ans,sum,p=1000000000,q=10000000000,flag,a[1000];

int main()
{
    scanf("%I64d%I64d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&a[i]);
        x+=a[i];
        ans=max(x,ans);
        p=min(x,p);
        if(0-p>m)
            flag=1;
        if(a[i]>0)
            q=min(m-a[i],q);
        if(a[i]>m)
            flag=1;
    }
    for(int i=1;i<=n;i++)
    {
        while(a[i]>=0)
        {
            sum+=a[i];
            i++;
        }
        if(sum>m)
        {
            flag=1;
            break;
        }
        sum=0;
    }
    if(flag)
        puts("0");
    else
    {
        if(p<0)
        {
            if(m-ans>=0)
                printf("%I64d\n",min(m-ans+1,min(m+p+1,q+1)));
            else
                puts("0");
        }
        else
        {
            if(m-ans>=0)
                printf("%I64d\n",min(m-ans+1,q+1));
            else
                puts("0");
        }
    }
    return 0;
}
//2019-07-21 20:32:24.484


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 1005;
ll math[MAXN];
int main()
{
    ll n,w;
    while(~scanf("%I64d%I64d",&n,&w))
    {
        ll sum=0;
        ll result1=0;
        ll result2=0;
        int flag;
        for(int i=0; i<n; i++)
            scanf("%I64d",&math[i]);
        for(int i=0; i<n; i++)
        {
            flag=0;
            sum+=math[i];
            if(sum<=0)
            {
                result1=max(-sum,result1);
                //printf("%I64d..\n",result1);
                if(result1>w)
                {
                    flag=1;
                    break;
                }
            }
            if(sum>w)
            {
                flag=1;
                break;
            }
            if(sum>0)
            {
                result2=max(result2,sum);
            }
        }
        //printf("%I64d %I64d\n",result1,result2);
        if(flag)printf("0\n");
        else
        {
            if(result1>(w-result2))
                printf("0\n");
            else
            {//printf("%I64d %I64d\n",result1,result2);
                printf("%I64d\n",(w-result2-result1)+1);}
        }
    }
    return 0;
}//2019-07-21 21:02:54.508


#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
    long long  s1[1005];
    long long n,w;
    while(~scanf("%I64d%I64d",&n,&w))
    {
        int c=0;
        long long minn=10000000000,maxn=-1;
        s1[0]=0;
        for(int i=1; i<=n; i++)
        {
            scanf("%I64d",&s1[i]);
            s1[i]+=s1[i-1];
            maxn=max(maxn,s1[i]);
            minn=min(minn,s1[i]);
        }
        if(maxn>w)
            printf("0\n");
        if(maxn<0)
        {
                minn=-(minn);
                printf("%d\n",w-minn+1);
        }
        if(maxn>=0&&maxn<=15)
        {
             if(minn<0)
             {
                minn=-(minn);
                printf("%d\n",(w-maxn)-minn+1);
             }
             else
                printf("%d\n",(w-maxn)+1);
        }
    }
    return 0;
}
//2019-07-22 00:34:27.647


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1005],sum[1005];
ll x[1005],y[1005];
int main()
{

    int n,m;
    cin>>n>>m;
    sum[0]=0;
    for(int i=1; i<=n; i++)
        cin>>a[i],sum[i]=sum[i-1]+a[i];

    int f=0;
    for(int i=1; i<=n; i++)
    {
        if(sum[i]>m)
        {
            f=1;
            break;
        }
        else if(sum[i]+m<0)
        {
            f=1;
            break;
        }
    }
    if(f)
    {
        puts("-1");
        return 0;
    }
    ll mi=1;
    int j=1;
    for(int i=1;i<=n;i++)
    {
      if(sum[i]<0)  mi=min(mi,sum[i]);
      else
      x[j++]=m-sum[i];
    }
    sort(x+1,x+j);
    int ans=x[1]+mi+1;
    if(ans<0)
        puts("-1");
    else cout<<ans<<endl;

    return 0;

}
//2019-07-21 20:18:11.219


#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
long long w;
long long str[1005];
long long sum[1005];
int main()
{
    scanf("%d%I64d",&n,&w);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&str[i]);
    }
    long long ans1=str[1];
    long long ans2=str[1];
    for(int i=1; i<=n; i++)
    {
        sum[i]=sum[i-1]+str[i];
        ans1=min(ans1,sum[i]);
        ans2=max(ans2,sum[i]);
    }
    long long x,y;
    x=max(-ans1,-ans2);
    y=min(w-ans1,w-ans2);
    if(x>y)
        puts("0");
    else if(y<0)
        puts("0");
    else if(x>w)
        puts("0");
    else
    {
        x=(x<0?0:x);
        y=(y>=w?w:y);
        printf("%I64d\n",y-x+1);
    }
    return 0;
}
//2019-07-21 22:12:24.516


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[1005];
int main()
{
    int n, m, x;
    scanf("%d%d", &n, &m);
    int flag = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &x);
        a[i] = x + a[i - 1];
        if(a[i] > m)
            flag = 1;
    }
    sort(a + 1, a + n + 1);
    int y;
    if(a[1] < 0)
        x = -a[1];
    else
        x = 0;
    y = m - a[n];
    if(flag == 1)
        printf("0");
    else
        printf("%d", y - x + 1);
    return 0;
}
//2019-07-21 21:05:14.674


#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
long long w;
long long str[1005];
long long sum[1005];
int main()
{
    scanf("%d%I64d",&n,&w);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&str[i]);
    }
    long long ans1=str[1];
    long long ans2=str[1];
    for(int i=1; i<=n; i++)
    {
        sum[i]=sum[i-1]+str[i];
        ans1=min(ans1,sum[i]);
        ans2=max(ans2,sum[i]);
    }
    long long x,y;
    x=-ans1;
    y=w-ans2;
    if(x>y)
        printf("0\n");
    else
    {
        if(y<0)
            printf("0\n");
        else
        {
            y=(y>=w?w:y);
            x=(x<0?0:x);
            printf("%I64d\n",y-x+1);
        }
    }
    return 0;
}
//2019-07-21 20:26:06.308


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    for(int i = 1; i <= 3; i++){
        cout << "HUIXINNIUBI" << endl;
    }
    return 0;
}
//2019-07-21 21:00:36.029


#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
long long w;
long long str[1005];
long long sum[1005];
int main()
{
    scanf("%d%I64d",&n,&w);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&str[i]);
    }
    long long ans1=str[1];
    long long ans2=str[1];
    for(int i=1; i<=n; i++)
    {
        sum[i]=sum[i-1]+str[i];
        ans1=min(ans1,sum[i]);
        ans2=max(ans2,sum[i]);
    }
    long long x,y;
    x=max(-ans1,-ans2);
    y=min(w-ans1,w-ans2);
    if(x>y)
        puts("0");
    else if(y<0)
        puts("0");
    else if(x>w)
        puts("0");
    else
    {
        x=(x<0?0:x);
        y=(y>=w?w:y);
        printf("%I64d\n",y-x+1);
    }
    return 0;
}
//2019-07-21 20:46:49.555


#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int INF = 0x3F3F3F3F;
const int N = 1005;

int a[N];

int main() {
    ios::sync_with_stdio(false);
    int n, w;
    cin >> n >> w;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) a[i] += a[i - 1];
    int Max = *max_element(a + 1, a + n + 1);
    int Min = *min_element(a + 1, a + n + 1);
    // if Max > 0, 一开始至多有 w - Max 人
    // if Min < 0, 一开始至少有 -Min 人
    int left, right;
    if (Min < 0) {
        left = -Min;
    } else {
        left = 0;
    }
    if (Max > 0) {
        right = w - Max;
    } else {
        right = w;
    }
    if (right < 0) {
        cout << "0\n";
    } else {
        cout << right - left + 1 << endl;
    }
    return 0;
}//2019-07-21 20:03:02.988


#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
long long w;
long long str[1005];
long long sum[1005];
int main()
{
    scanf("%d%I64d",&n,&w);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&str[i]);
    }
    long long ans1=str[1];
    long long ans2=str[1];
    for(int i=1; i<=n; i++)
    {
        sum[i]=sum[i-1]+str[i];
        ans1=min(ans1,sum[i]);
        ans2=max(ans2,sum[i]);
    }
    long long x,y;
    x=max(-ans1,-ans2);
    y=min(w-ans1,w-ans2);
    if(x>y)
        puts("0");
    else if(y<0)
        puts("0");
    else
    {
        x=(x<0?0:x);
        y=(y>=w?w:y);
        printf("%I64d\n",y-x+1);
    }
    return 0;
}
//2019-07-21 20:43:07.798


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1005],sum[1005];
double x[1005],y[1005];
int main()
{

    int n,m;
    cin>>n>>m;
    sum[0]=0;
    for(int i=1; i<=n; i++)
        cin>>a[i],sum[i]=sum[i-1]+a[i];

    int f=0;
    for(int i=1; i<=n; i++)
    {
        if(sum[i]>m)
        {
            f=1;
            break;
        }
        else if(sum[i]+m<0)
        {
            f=1;
            break;
        }
    }
    if(f)
    {
        puts("0");
        return 0;
    }
    ll mi=1;
    int j=1;
    for(int i=1;i<=n;i++)
    {
      if(sum[i]<0)  mi=min(mi,sum[i]);
      else
      x[j++]=m-sum[i];
    }
    sort(x+1,x+j);
    if(mi==1) mi=0;
    ll ans=x[1]+mi+1;

    if(ans<0)
        puts("0");
    else cout<<ans<<endl;

    return 0;

}
//2019-07-21 20:32:02.214


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
long long n,m,x,ma,mi,l,r,y;

int main()
{
    scanf("%I64d%I64d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&y);
        x+=y;
        ma=max(x,ma);
        mi=min(x,mi);
    }
    l=max(-ma,-mi);
    r=min(m-ma,m-mi);
    if(l>r||l>m||r<0)
        puts("0");
    else
        printf("%d\n",r-l+1);
    return 0;
}
//2019-07-21 21:56:00.463


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
long long n,m,x,ans,p,flag,a[1000];

int main()
{
    scanf("%I64d%I64d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&a[i]);
        x+=a[i];
        ans=max(x,ans);
        p=min(x,p);
    }
    if(p<0)
    {
        if(m-ans>=0)
            printf("%I64d\n",m+p+1);
        else
            puts("0");
    }
    else
    {
        if(m-ans>=0)
            printf("%I64d\n",m-ans+1);
        else
            puts("0");
    }
    return 0;
}
//2019-07-21 20:01:52.944


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
long long n,m,x,ans,p,flag,a[1000];

int main()
{
    scanf("%I64d%I64d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&a[i]);
        x+=a[i];
        ans=max(x,ans);
        p=min(x,p);
    }
    if(p<0)
    {
        if(m-ans>=0)
            printf("%d\n",min(m-ans+1,m+p+1));
        else
            puts("0");
    }
    else
    {
        if(m-ans>=0)
            printf("%d\n",m-ans+1);
        else
            puts("0");
    }
    return 0;
}
//2019-07-21 19:55:06.703


#include<stdio.h>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<iostream>
using namespace std;
#define mes(x,a); memset(x,a,sizeof(x));
#define lowbit(x)  x & (-x)
const int maxn=1e5+5;
const int maxm=2e6+5;
const int inf =0x3f3f3f3f;
const double eps=1e-9;
const double pi=acos(-1);
int m,n,w;
bool vis[1005];
int a[10005];
bool judge1(int k)
{
    for(int i=1;i<=n;i++)
    {
        k+=a[i];
        if(k<0||k>w)
            return 0;
    }
    return 1;
}
int op(int k)
{
    for(int i=1;i<=n;i++)
    {
        k+=a[i];
        if(k<0)
            return k+1;
        if(k>w)
            return -1;
    }
    return -2;
}
int main()
{
    scanf("%d %d",&n,&w);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
    int ans=-1;
    for(int i=0;i<=w;i++)
    {
        int z=op(i);
        if(z==-2)
        {
            ans=i;
            break;
        }
        else if(z==-1)
            break;
        else
            i+=z;
    }
    int l,r,mid;
    l=ans-1,r=w+1;
    while(l+1<r)
    {
        mid=(l+r)>>1;
        if(judge1(mid))
            l=mid;
        else
            r=mid;
    }
    printf("%d\n",l-ans+1);
}
//2019-07-21 19:53:17.752


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
const int MAX=1e3+5;
long long record[MAX];
int main()
{
  int n;
  long long w;
  cin >> n >> w;
  long long mi=0, ma=0;
  for (int i=1; i<=n; i++)
  {
    scanf("%I64d", &record[i]);
    record[i] += record[i-1];
    mi = min(record[i], mi);
    ma = max(record[i], ma);
  }
  if (w+mi<0) cout << 0 << endl;
  else if (w<ma) cout << 0 << endl;
  else if (ma-mi>w) cout << 0 << endl;
  else if (mi>=0) cout << w-ma+1 << endl;
  else if (ma<=0) cout << w+mi+1 << endl;
  else cout << abs(w-ma+mi)+1 << endl;

  return 0;
}
//2019-07-22 00:46:20.453


#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
long long w;
long long str[1005];
long long sum[1005];
int main()
{
    scanf("%d%I64d",&n,&w);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&str[i]);
    }
    long long ans1=str[1];
    long long ans2=str[1];
    for(int i=1; i<=n; i++)
    {
        sum[i]=sum[i-1]+str[i];
        ans1=min(ans1,sum[i]);
        ans2=max(ans2,sum[i]);
    }
    long long x,y;
    x=max(-ans1,-ans2);
    y=min(w-ans1,w-ans2);
    if(x>y)
        puts("0");
    else if(y<0)
        puts("0");
    else if(x>m)
        puts("0");
    else
    {
        x=(x<0?0:x);
        y=(y>=w?w:y);
        printf("%I64d\n",y-x+1);
    }
    return 0;
}
//2019-07-21 20:46:22.487


#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
long long w;
long long str[1005];
long long sum[1005];
int main()
{
    scanf("%d%I64d",&n,&w);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&str[i]);
    }
    long long ans1=str[1];
    long long ans2=str[1];
    for(int i=1; i<=n; i++)
    {
        sum[i]=sum[i-1]+str[i];
        ans1=min(ans1,sum[i]);
        ans2=max(ans2,sum[i]);
    }
    long long x,y;
    x=max(-ans1,-ans2);
    y=min(w-ans1,w-ans2);
    if(x>y)
        puts("0");
    else
    {
        x=(x<0?0:x);
        y=(y>=w?w:y);
        printf("%I64d\n",y-x+1);
    }
    return 0;
}
//2019-07-21 20:42:04.771


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int c=0,n,w,i,j,mx=-2000000000,mn=2000000000,f=0,x,y,z=0;
    cin>>n>>w;
    for(i=0;i<n;i++){
        cin>>x;
        c+=x;
        mx=max(c,mx);
        mn=min(c,mn);
        if(mx>w) f=1;
        if(abs(mn)>w) f=1;
        if(c<0) z=1;
    }
    if(z==0) mn=0;
    //cout<<abs(mn)<<" "<<mx<<"\n";
    if(f) {cout<<0; return 0;}
    if(mx<0) cout<<w-abs(mn)+1;
    else cout<<w-mx+1-abs(mn);
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long c=0,n,w,i,j,mx=-2000000000000,mn=2000000000000,f=0,x,y,z=0;
    cin>>n>>w;
    for(i=0;i<n;i++){
        cin>>x;
        c+=x;
        mx=max(c,mx);
        mn=min(c,mn);
        if(mx>w) f=1;
        if(abs(mn)>w) f=1;
        if(c<0) z=1;
    }
    if(f) {cout<<0; return 0;}
    int p,q;
    if(mn<0) p=-1*mn;
    else p=0;
    if(mx<=0) q=w;
    else q=w-mx;
    if(p>q) cout<<0;
    else cout<<q-p+1;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long c=0,n,w,i,j,mx=-2000000000000,mn=2000000000000,f=0,x,y,z=0;
    cin>>n>>w;
    for(i=0;i<n;i++){
        cin>>x;
        c+=x;
        mx=max(c,mx);
        mn=min(c,mn);
        if(mx>w) f=1;
        if(abs(mn)>w) f=1;
        if(c<0) z=1;
    }
    //if(z==0) mn=0;
    cout<<mn<<" "<<mx<<"\n";
    if(f) {cout<<0; return 0;}
    if(mx<0) cout<<w-abs(mn)+1;
    else if(mn>=0) cout<<w-abs(mx)+1;
    else cout<<w-mx+1-abs(mn);
    //else cout<<0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int c=0,n,w,i,j,mx=-2000000000,mn=2000000000,f=0,x,y,z=0;
    cin>>n>>w;
    for(i=0;i<n;i++){
        cin>>x;
        c+=x;
        mx=max(c,mx);
        mn=min(c,mn);
        if(mx>w) f=1;
        if(abs(mn)>w) f=1;
        if(c<0) z=1;
    }
    //if(z==0) mn=0;
    //cout<<abs(mn)<<" "<<mx<<"\n";
    if(f) {cout<<0; return 0;}
    if(mx<0) cout<<w-abs(mn)+1;
    else if(mn>0) cout<<w-mx+1;
    else cout<<w-mx+1-abs(mn);
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int c=0,n,w,i,j,mx=-2000000000,mn=2000000000,f=0,x,y,z=0;
    cin>>n>>w;
    for(i=0;i<n;i++){
        cin>>x;
        c+=x;
        mx=max(c,mx);
        mn=min(c,mn);
        if(mx>w) f=1;
        if(abs(mn)>w) f=1;
        if(c<0) z=1;
    }
    if(z==0) mn=0;
    //cout<<abs(mn)<<" "<<mx<<"\n";
    if(f) {cout<<0; return 0;}
    if(mx<0) cout<<w-abs(mn)+1;
    else if(mn>0) cout<<w-mx+1;
    else cout<<w-mx+1-abs(mn);
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long c=0,n,w,i,j,mx=-2000000000000,mn=2000000000000,f=0,x,y,z=0;
    cin>>n>>w;
    for(i=0;i<n;i++){
        cin>>x;
        c+=x;
        mx=max(c,mx);
        mn=min(c,mn);
        if(mx>w) f=1;
        if(abs(mn)>w) f=1;
        if(c<0) z=1;
    }
    //if(z==0) mn=0;
    //cout<<mn<<" "<<mx<<"\n";
    if(f) {cout<<0; return 0;}
    if(mx<0) cout<<w-abs(mn)+1;
    else if(mn>=0) cout<<w-abs(mx)+1;
    else cout<<w-mx+1-abs(mn);
    //else cout<<0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long c=0,n,w,i,j,mx=-2000000000000,mn=2000000000000,f=0,x,y,z=0;
    cin>>n>>w;
    for(i=0;i<n;i++){
        cin>>x;
        c+=x;
        mx=max(c,mx);
        mn=min(c,mn);
        if(mx>w) f=1;
        if(abs(mn)>w) f=1;
        if(c<0) z=1;
    }
    //if(z==0) mn=0;
    //cout<<abs(mn)<<" "<<mx<<"\n";
    if(f) {cout<<0; return 0;}
    if(mx<0) cout<<w-abs(mn)+1;
    else if(mn>0) cout<<w-mx+1;
    else cout<<w-mx+1-abs(mn);
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long c=0,n,w,i,j,mx=-2000000000000,mn=2000000000000,f=0,x,y,z=0;
    cin>>n>>w;
    for(i=0;i<n;i++){
        cin>>x;
        c+=x;
        mx=max(c,mx);
        mn=min(c,mn);
        if(mx>w) f=1;
        if(abs(mn)>w) f=1;
        if(c<0) z=1;
    }
    //if(z==0) mn=0;
    //cout<<abs(mn)<<" "<<mx<<"\n";
    if(f) {cout<<0; return 0;}
    if(mx<0) cout<<w-abs(mn)+1;
    else if(mn>=0) cout<<w-mx+1;
    else cout<<w-mx+1-abs(mn);
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long c=0,n,w,i,j,mx=-2000000000,mn=2000000000,f=0,x,y,z=0;
    cin>>n>>w;
    for(i=0;i<n;i++){
        cin>>x;
        c+=x;
        mx=max(c,mx);
        mn=min(c,mn);
        if(mx>w) f=1;
        if(abs(mn)>w) f=1;
        if(c<0) z=1;
    }
    //if(z==0) mn=0;
    //cout<<abs(mn)<<" "<<mx<<"\n";
    if(f) {cout<<0; return 0;}
    if(mx<0) cout<<w-abs(mn)+1;
    else if(mn>0) cout<<w-mx+1;
    else cout<<w-mx+1-abs(mn);
}


#include<iostream>
#include<algorithm>
#include<iomanip>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <new>
#include <cmath>
#include<fstream>
using namespace std;
#define Precision(i) cout << fixed << setprecision(i)
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;

const ll MAXN = 1e6 + 20, mod = 1e9 + 7, inf = 1e9;
ll n, m, x1, yy, x2, y2, x, y , d, z , t, pos, ans1, ans2, a[MAXN], sum, maxi;
bool mark[MAXN];
vector <ll> v, good;
string s;
bool checkmin(ll pp)
{
	if (pp < 0)
		{
			return false;
		}
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp < 0)
		{
			return false;
		}
	}
	return true;
}
bool checkmax(ll pp)
{
	if (pp > d)
		{
			return false;
		}
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp > d)
		{
			return false;
		}
	}
	return true;
}
int main()
{
//	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	ll e = d, b = -1, mid = 0; ///minimum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmin(mid))
		{
			e = mid;
		}
		else
		{
			b = mid;
		}
	}
	ans1 = e;
	e = d + 1, b = 0, mid = 0; ///maximum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmax(mid))
		{
			b = mid;
		}
		else
		{
			e = mid;
		}
	}
	ans2 = b;
	cout << ans2 - ans1 + 1;
}


#include<iostream>
#include<algorithm>
#include<iomanip>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <new>
#include <cmath>
#include<fstream>
using namespace std;
#define Precision(i) cout << fixed << setprecision(i)
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;

const ll MAXN = 1e6 + 20, mod = 1e9 + 7, inf = 1e9;
ll n, m, x1, yy, x2, y2, x, y , d, z , t, pos, ans1, ans2, a[MAXN], sum, maxi;
bool mark[MAXN];
vector <ll> v, good;
string s;
bool checkmin(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp < 0)
		{
			return false;
		}
	}
	return true;
}
bool checkmax(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp > d)
		{
			return false;
		}
	}
	return true;
}
int main()
{
//	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		x += a[i];
	}
	if (x  < 0 || x > d)
	{
		cout << 0;
		return 0;
	}
	ll e = d, b = -1, mid = 0; ///minimum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmin(mid))
		{
			e = mid;
		}
		else
		{
			b = mid;
		}
	}
	ans1 = e;
	e = d + 1, b = 0, mid = 0; ///maximum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmax(mid))
		{
			b = mid;
		}
		else
		{
			e = mid;
		}
	}
	ans2 = b;
	cout << ans2 - ans1 + 1;
}


#include<iostream>
#include<algorithm>
#include<iomanip>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <new>
#include <cmath>
#include<fstream>
using namespace std;
#define Precision(i) cout << fixed << setprecision(i)
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;

const ll MAXN = 1e6 + 20, mod = 1e9 + 7, inf = 1e9;
ll n, m, x1, yy, x2, y2, x, y , d, z , t, pos, ans1, ans2, a[MAXN], sum, maxi;
bool mark[MAXN];
vector <ll> v, good;
string s;
bool checkmin(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp < 0)
		{
			return false;
		}
	}
	return true;
}
bool checkmax(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp > d)
		{
			return false;
		}
	}
	return true;
}
int main()
{
//	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (abs(a[i]) > d)
		{
			cout << 0;
			return 0;
		}
		x += a[i];
		if (x < 0 || x > d)
		{
		cout << 0;
		return 0;
		}
	}
	x = 0;
	ll e = d, b = -1, mid = 0; ///minimum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmin(mid))
		{
			e = mid;
		}
		else
		{
			b = mid;
		}
	}
	ans1 = e;
	e = d + 1, b = 0, mid = 0; ///maximum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmax(mid))
		{
			b = mid;
		}
		else
		{
			e = mid;
		}
	}
	ans2 = b;
	cout << ans2 - ans1 + 1;
}


#include<iostream>
#include<algorithm>
#include<iomanip>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <new>
#include <cmath>
#include<fstream>
using namespace std;
#define Precision(i) cout << fixed << setprecision(i)
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;

const ll MAXN = 1e6 + 20, mod = 1e9 + 7, inf = 1e9;
ll n, m, x1, yy, x2, y2, x, y , d, z , t, pos, ans1, ans2, a[MAXN], sum, maxi;
bool mark[MAXN];
vector <ll> v, good;
string s;
bool checkmin(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp < 0)
		{
			return false;
		}
	}
	return true;
}
bool checkmax(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp > d)
		{
			return false;
		}
	}
	return true;
}
int main()
{
//	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	ll e = d, b = -1, mid = 0; ///minimum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmin(mid))
		{
			e = mid;
		}
		else
		{
			b = mid;
		}
	}
	ans1 = e;
	e = d + 1, b = 0, mid = 0; ///maximum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmax(mid))
		{
			b = mid;
		}
		else
		{
			e = mid;
		}
	}
	ans2 = b;
	if (checkmin(ans1) && checkmin(ans2) && checkmax(ans1) && checkmax(ans2))
	cout << ans2 - ans1 + 1;
	else
	{
		cout << 0;
	}
}


#include<iostream>
#include<algorithm>
#include<iomanip>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <new>
#include <cmath>
#include<fstream>
using namespace std;
#define Precision(i) cout << fixed << setprecision(i)
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;

const ll MAXN = 1e6 + 20, mod = 1e9 + 7, inf = 1e9;
ll n, m, x1, yy, x2, y2, x, y , d, z , t, pos, ans1, ans2, a[MAXN], sum, maxi;
bool mark[MAXN];
vector <ll> v, good;
string s;
bool checkmin(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp < 0)
		{
			return false;
		}
	}
	return true;
}
bool checkmax(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp > d)
		{
			return false;
		}
	}
	return true;
}
int main()
{
//	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (abs(a[i]) > d)
		{
			cout << 0;
			return 0;
		}
	}
	ll e = d, b = -1, mid = 0; ///minimum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmin(mid))
		{
			e = mid;
		}
		else
		{
			b = mid;
		}
	}
	ans1 = e;
	e = d + 1, b = 0, mid = 0; ///maximum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmax(mid))
		{
			b = mid;
		}
		else
		{
			e = mid;
		}
	}
	ans2 = b;
	cout << ans2 - ans1 + 1;
}


#include<iostream>
#include<algorithm>
#include<iomanip>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <new>
#include <cmath>
#include<fstream>
using namespace std;
#define Precision(i) cout << fixed << setprecision(i)
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;

const ll MAXN = 1e6 + 20, mod = 1e9 + 7, inf = 1e9;
ll n, m, x1, yy, x2, y2, x, y , d, z , t, pos, ans1, ans2, a[MAXN], sum, maxi;
bool mark[MAXN];
vector <ll> v, good;
string s;
bool checkmin(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp < 0)
		{
			return false;
		}
	}
	return true;
}
bool checkmax(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp > d)
		{
			return false;
		}
	}
	return true;
}
int main()
{
//	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	ll e = d, b = -1, mid = 0; ///minimum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmin(mid))
		{
			e = mid;
		}
		else
		{
			b = mid;
		}
	}
	ans1 = e;
	e = d + 1, b = 0, mid = 0; ///maximum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmax(mid))
		{
			b = mid;
		}
		else
		{
			e = mid;
		}
	}
	ans2 = b;
	if (ans2 == 0)
	{
		cout << 0;
		return 0;
	}
	cout << ans2 - ans1 + 1;
}


#include<iostream>
#include<algorithm>
#include<iomanip>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <new>
#include <cmath>
#include<fstream>
using namespace std;
#define Precision(i) cout << fixed << setprecision(i)
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;

const ll MAXN = 1e6 + 20, mod = 1e9 + 7, inf = 1e9;
ll n, m, x1, yy, x2, y2, x, y , d, z , t, pos, ans1, ans2, a[MAXN], sum, maxi;
bool mark[MAXN];
vector <ll> v, good;
string s;
bool checkmin(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp < 0)
		{
			return false;
		}
	}
	return true;
}
bool checkmax(ll pp)
{
	for (int i = 0; i < n; i++)
	{
		pp += a[i];
		if (pp > d)
		{
			return false;
		}
	}
	return true;
}
int main()
{
//	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (abs(a[i]) > d)
		{
			cout << 0;
			return 0;
		}
		x += a[i];
	}
	if (x < 0 || x > d)
	{
		cout << 0;
		return 0;
	}
	x = 0;
	ll e = d, b = -1, mid = 0; ///minimum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmin(mid))
		{
			e = mid;
		}
		else
		{
			b = mid;
		}
	}
	ans1 = e;
	e = d + 1, b = 0, mid = 0; ///maximum
	while (e - b > 1)
	{
		mid = e + b >> 1;
		if (checkmax(mid))
		{
			b = mid;
		}
		else
		{
			e = mid;
		}
	}
	ans2 = b;
	cout << ans2 - ans1 + 1;
}


#include <cstdio>

int main()
{
    int max = -2e9, min = 2e9;
    int n, w, i;
    scanf("%d%d", &n, &w);

    int sum = 0, tmp;
    for (i = 0; i < n; ++i)
    {
        scanf("%d", &tmp);
        sum += tmp;
        if (sum < min)
        {
            min = sum;
            if (min < -w)
                break;
        }
        if (sum > max)
        {
            max = sum;
            if (max > w)
                break;
        }
    }

    if (i != n || w - max < ((min > 0) ? 0 : -min))
        puts("0");
    else
        printf("%d\n", (w - max) + ((min > 0) ? 0 : -min) + 1);

    return 0;
}


#include <cstdio>

int main()
{
    int max = -2e9, min = 2e9;
    int n, w, i;
    scanf("%d%d", &n, &w);

    int sum = 0, tmp;
    for (i = 0; i < n; ++i)
    {
        scanf("%d", &tmp);
        sum += tmp;
        if (sum < min)
        {
            min = sum;
            if (min < -w)
                break;
        }
        if (sum > max)
        {
            max = sum;
            if (max > w)
                break;
        }
    }

    if (i != n || w - max < -min)
        puts("0");
    else
        printf("%d\n", (w - max) + ((min > 0) ? 0 : min) + 1);

    return 0;
}


#include <cstdio>
#define N 1005

int main()
{
    int max = 2e9, min = 2e9;
    int n, w, i;
    scanf("%d%d", &n, &w);

    int sum = 0, tmp;
    for (i = 0; i < n; ++i)
    {
        scanf("%d", &tmp);
        sum += tmp;
        if (sum < min)
        {
            min = sum;
            if (min < -w)
                break;
        }
        if (sum > max)
        {
            max = sum;
            if (max > w)
                break;
        }
    }

    if (i != n)
        puts("0");
    else
        printf("%d\n", w - max + (min > 0 ? 0 : min) + 1);

    return 0;
}


#include <cstdio>

int main()
{
    int max = -2e9, min = 2e9;
    int n, w, i;
    scanf("%d%d", &n, &w);

    int sum = 0, tmp;
    for (i = 0; i < n; ++i)
    {
        scanf("%d", &tmp);
        sum += tmp;
        if (sum < min)
        {
            min = sum;
            if (min < -w)
                break;
        }
        if (sum > max)
        {
            max = sum;
            if (max > w)
                break;
        }
    }

    if (i != n)
        puts("0");
    else
        printf("%d\n", w - max + (min > 0 ? 0 : min) + 1);

    return 0;
}


#include <cstdio>

int main()
{
    int max = -2e9, min = 2e9;
    int n, w, i;
    scanf("%d%d", &n, &w);

    int sum = 0, tmp;
    for (i = 0; i < n; ++i)
    {
        scanf("%d", &tmp);
        sum += tmp;
        if (sum < min)
        {
            min = sum;
            if (min < -w)
                break;
        }
        if (sum > max)
        {
            max = sum;
            if (max > w)
                break;
        }
    }

    max = (w < w - max) ? w : (w - max);
    min = min > 0 ? 0 : -min;
    if (i != n || max < min)
        puts("0");
    else
        printf("%d\n", max - min + 1);

    return 0;
}


#include <cstdio>

int main()
{
    int max = -2e9, min = 2e9;
    int n, w, i;
    scanf("%d%d", &n, &w);

    int sum = 0, tmp;
    for (i = 0; i < n; ++i)
    {
        scanf("%d", &tmp);
        sum += tmp;
        if (sum < min)
        {
            min = sum;
            if (min < -w)
                break;
        }
        if (sum > max)
        {
            max = sum;
            if (max > w)
                break;
        }
    }

    if (i != n || w - max < ((min > 0) ? 0 : -min))
        puts("0");
    else
        printf("%d\n", (w - max) + ((min > 0) ? 0 : min) + 1);

    return 0;
}


#include <cstdio>
#define N 1005

int main()
{
    int max = 2e9, min = 2e9;
    int n, w, i;
    scanf("%d%d", &n, &w);

    int sum = 0, tmp;
    for (i = 0; i < n; ++i)
    {
        scanf("%d", &tmp);
        sum += tmp;
        if (sum < min)
        {
            min = sum;
            if (min < -w)
                break;
        }
        if (sum > max)
        {
            max = sum;
            if (max > w)
                break;
        }
    }

    if (i != n)
        puts("0");
    else
        printf("%d\n", w - max + (min < 0 ? min : 0) + 1);

    return 0;
}


#include <bits/stdc++.h>

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

ll v[1005];
ll n,m;

pair<ll,ll> f(ll x) {
	pair<ll,ll> ret{0, 0};
	for(ll i = 0; i < n; i++) {
		x += v[i];
		ret.ff = min(ret.ff, x);
		ret.ss = max(ret.ss, x);
	}
	return ret;
}

int main() {
	scanf("%lld%lld", &n, &m);

	for(ll i = 0; i < n; i++)
		scanf("%lld", &v[i]);

	pair<ll,ll> r = f(0);
	if(r.ff < 0) r.ss += -r.ff, r.ff = 0;

	if(r.ss > m) printf("0\n");
	else printf("%lld\n", m-r.ss+1);

	return 0;
}


#include <bits/stdc++.h>

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

ll v[1005];
ll n,m;

pair<ll,ll> f(ll x) {
	pair<ll,ll> ret{0, 0};
	for(ll i = 0; i < n; i++) {
		x += v[i];
		ret.ff = min(ret.ff, x);
		ret.ss = max(ret.ss, x);
	}
	return ret;
}

int main() {
	scanf("%lld%lld", &n, &m);

	for(ll i = 0; i < n; i++)
		scanf("%lld", &v[i]);

	pair<ll,ll> r = f(0);
	if(r.ff < 0) r.ss += -r.ff, r.ff = 0;

	if(r.ss > m) prllf("0\n");
	else prllf("%lld\n", m-r.ss+1);

	return 0;
}


#include <bits/stdc++.h>

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

int v[1005];
int n,m;

bool f(int x, bool flag = 0) {
	for(int i = 0; i < n; i++) {
		x += v[i];
		if(x < 0 or ((x > m) & flag)) return false;
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);

	for(int i = 0; i < n; i++)
		scanf("%d", &v[i]);

	int l = 0, r = m;
	while(l+1 < r) {
		int mid = (l+r)/2;

		if(f(mid,1)) l = mid;
		else r = mid-1;
	}
	if(l+1 <= m && f(l+1, 1)) l++;
	int maxx = l;

	l = 0, r = m;
	while(l+1 < r) {
		int mid = (l+r)/2;
		// printf("dsa %d %d\n", mid, f(mid, 0));

		if(f(mid, 0)) r = mid;
		else l = mid+1;
	}
	if(r-1 >= 0 && f(r-1, 0)) r--;
	int minn = r;

	printf("%d\n", max(maxx-minn+1, 0));

	return 0;
}


#include <bits/stdc++.h>

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

int v[1005];
int n,m;

pair<int,int> f(int x) {
	pair<int,int> ret{1e9, -1e9};
	for(int i = 0; i < n; i++) {
		x += v[i];
		ret.ff = min(ret.ff, x);
		ret.ss = max(ret.ss, x);
	}
	return ret;
}

int main() {
	scanf("%d%d", &n, &m);

	for(int i = 0; i < n; i++)
		scanf("%d", &v[i]);

	pair<int,int> r = f(0);
	if(r.ff < 0) r.ss += -r.ff, r.ff = 0;

	if(r.ss > m) printf("0\n");
	else printf("%d\n", m-r.ss+1);

	return 0;
}


#include <bits/stdc++.h>

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

int v[1005];
int n,m;

bool f(int x, bool flag = 0) {
	for(int i = 0; i < n; i++) {
		x += v[i];
		if(x < 0 or ((x > m) & flag)) return false;
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);

	for(int i = 0; i < n; i++)
		scanf("%d", &v[i]);

	int l = 0, r = m;
	while(l+1 < r) {
		int mid = (l+r)/2;

		if(f(mid,1)) l = mid;
		else r = mid-1;
	}
	if(l+1 <= m && f(l+1, 1)) l++;
	int maxx = l;

	l = 0, r = m;
	while(l+1 < r) {
		int mid = (l+r)/2;
		// printf("dsa %d %d\n", mid, f(mid, 0));

		if(f(mid, 0)) r = mid;
		else l = mid+1;
	}
	if(r-1 >= 0 && f(r-1, 0)) r--;
	int minn = r;

	printf("%d %d\n", maxx ,minn);
	printf("%d\n", max(maxx-minn+1, 0));

	return 0;
}


#include <bits/stdc++.h>

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

int v[1005];
int n,m;

bool f(int x, bool flag = 0) {
	for(int i = 0; i < n; i++) {
		x += v[i];
		if(x < 0 or ((x > m) & flag)) return false;
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);

	for(int i = 0; i < n; i++)
		scanf("%d", &v[i]);

	int l = 0, r = m;
	while(l+1 < r) {
		int mid = (l+r)/2;

		if(f(mid,1)) l = mid;
		else r = mid-1;
	}
	if(l+1 <= m && f(l+1, 1)) l++;
	int maxx = l;

	l = 0, r = m;
	while(l+1 < r) {
		int mid = (l+r)/2;
		// printf("dsa %d %d\n", mid, f(mid, 0));

		if(f(mid, 0)) r = mid;
		else l = mid+1;
	}
	if(r-1 >= 0 && f(r-1, 0)) r--;
	int minn = r;

	int ans = max(maxx-minn+1, 0);
	if(!f(maxx, 1) or !f(minn, 1)) ans = 0;
	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

int v[1005];
int n,m;

pair<int,int> f(int x) {
	pair<int,int> ret{0, 0};
	for(int i = 0; i < n; i++) {
		x += v[i];
		ret.ff = min(ret.ff, x);
		ret.ss = max(ret.ss, x);
	}
	return ret;
}

int main() {
	scanf("%d%d", &n, &m);

	for(int i = 0; i < n; i++) {
		scanf("%d", &v[i]);
		assert(abs(v[i]) <= 1000000);
	}

	pair<int,int> r = f(0);
	if(r.ff < 0) r.ss += -r.ff, r.ff = 0;

	if(r.ss > m) printf("0\n");
	else printf("%d\n", m-r.ss+1);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=0;
    int mn=0;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx+arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {x=1;cout<<0<<endl;}
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=0;
           if(mx<=0)
           rg=w;
           else
           rg=w-mx;
       }

    }
    if(x==0)
    {if(rg>=lg)
    cout<<(rg-lg+1)<<endl;
    else
    cout<<0<<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=0;
    int mn=0;int mini= INT_MAX;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx+arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=max(0,lg);
           if(mx<=0)
           rg=q;
           else
           rg=q-mx;
           if(rg>=lg)
            mini= min(mini,(rg-lg+1));
             else
            {cout<<0<<endl;
            return 0;
            }
    }
       }
       cout<<mini<<endl;

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=q;
    int mn=0;int mini= INT_MAX;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx-arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=0;
           if(mx<=0)
           rg=q;
           else
           rg=q-mx;
           if(rg>=lg)
            mini= min(mini,(rg-lg+1));
             else
            {cout<<0<<endl;
            return 0;
            }
    }
       }
       cout<<mini<<endl;

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=0;
    int mn=0;int mini= INT_MAX;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx+arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=max(0,lg);
           if(mx<=0)
           rg=min(q,rg);
           else
           rg=q-mx;
           if(rg>=lg)
            mini= min(mini,(rg-lg+1));
             else
            {cout<<0<<endl;
            return 0;
            }
    }
       }
       cout<<mini<<endl;

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
//#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define sll                     set<ll>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define umcl                    um<char,ll>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

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

int main()
{
	fastIO
	inp_out();
	ll n,w;
	cin>>n>>w;
	vll a(n);
	for(ll i=0;i<n;++i)
	{
		cin>>a[i];
	}

	ll val=0,mx=w,mn=0;
	for(ll i=0;i<n;++i)
	{

		val+=a[i];
		if(val>w)
		{
			cout<<0;
			return 0;
		}

		ll val1=min(w,w-val);
		ll val2=max(0ll,-val);

		mx=min(val1,mx);
		mn=max(val2,mn);
	}

	cout<<max(0ll,mx-mn+1);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=0;
    int mn=0;int mini= INT_MAX;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx+arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=max(0,lg);
           if(mx<=0)
           rg=min(rg,q);
           else
           rg=q-mx;
           if(rg>=lg)
            mini= min(mini,(rg-lg+1));
             else
            {cout<<0<<endl;
            return 0;
            }
    }
       }
       cout<<mini<<endl;

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=q;
    int mn=0;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx-arr[i];
       mn= mn -arr[i];
       if(mx>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=0;
           if(mx<=0)
           rg=q;
           else
           rg=q-mx;
       }

    }

    {if(rg>=lg)
    cout<<(rg-lg+1)<<endl;
    else
    cout<<0<<endl;
    }
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=0;
    int mn=0;int mini= INT_MAX;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx+arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=max(0,lg);
           if(mx<=0)
           rg=min(rg,q);
           else
           rg=q-mx;
            }
    }if(lg>rg)
    cout<<0<<endl;
    else
    cout<<(rg-lg+1)<<endl;
       }


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=w;
    int mn=0;int mini= INT_MAX;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  x =x+arr[i];

       if(x>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           lg=max(-x,lg);
           rg=min(q-x,q);

           mx = min(mx,rg);
           mn= max(mn,lg);
            }
    }
    cout<<max(0,(mx-mn+1))<<endl;
    return 0;
       }


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=0;
    int mn=0;int mini= INT_MAX;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx+arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=0;
           if(mx<=0)
           rg=q;
           else
           rg=q-mx;
           if(rg>=lg)
            mini= min(mini,(rg-lg+1));
             else
            {cout<<0<<endl;
            return 0;
            }
    }
       }
       cout<<mini<<endl;

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=0;
    int mn=0;int mini= INT_MAX;
    int lg=0;int x=0;
    int rg=q;
    for(int i=0;i<n;i++)
    {  mx =mx+arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=max(0,lg);
           if(mx<=0)
           rg=min(rg,q);
           else
           rg=q-mx;
           if(rg>=lg)
            mini= min(mini,(rg-lg+1));
             else
            {cout<<0<<endl;
            return 0;
            }
    }
       }
       cout<<mini<<endl;

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=0;
    int mn=0;int mini= INT_MAX;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx+arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           if(mn<0)
           lg=max(lg, -mn);
           else
           lg=0;
           if(mx<=0)
           rg=q;
           else
           rg=min(q,q-mx);
           if(rg>=lg)
            mini= min(mini,(rg-lg+1));
             else
            {cout<<0<<endl;
            return 0;
            }
    }
       }
       cout<<mini<<endl;

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=q;
    int mn=0;int mini= INT_MAX;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx-arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=0;
           if(mx<=0)
           rg=q;
           else
           rg=mx;
           if(rg>=lg)
            mini= min(mini,(rg-lg+1));
             else
            {cout<<0<<endl;
            return 0;
            }
    }
       }
       cout<<mini<<endl;

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=0;
    int mn=0;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx+arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {x=1;cout<<0<<endl;}
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=0;
           if(mx<=0)
           rg=q;
           else
           rg=q-mx;
       }

    }
    if(x==0)
    {if(rg>=lg)
    cout<<(rg-lg+1)<<endl;
    else
    cout<<0<<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=q;
    int mn=0;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx-arr[i];
       mn= mn +arr[i];
       if(mx>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=0;
           if(mx<=0)
           rg=q;
           else
           rg=q-mx;
       }

    }

    {if(rg>=lg)
    cout<<(rg-lg+1)<<endl;
    else
    cout<<0<<endl;
    }
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=0;
    int mn=0;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  mx =mx+arr[i];
       mn= mn -arr[i];
       if(mx>q)
       {x=1;cout<<0<<endl;}
       else
       {
           if(mn<0)
           lg= -mn;
           else
           lg=0;
           if(mx<=0)
           rg=q;
           else
           rg=q-mx;
       }

    }
    if(x==0)
    {if(rg>=lg)
    cout<<(rg-lg+1)<<endl;
    else
    cout<<0<<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int mx=q;
    int mn=0;int mini= INT_MAX;
    int lg=0;int x=0;
    int rg=0;
    for(int i=0;i<n;i++)
    {  x =x+arr[i];

       if(x>q)
       {cout<<0<<endl;
           return 0;
       }
       else
       {
           lg=max(-x,lg);
           rg=min(q-x,q);

           mx = min(mx,rg);
           mn= max(mn,lg);
            }
    }
    cout<<max(0,(mx-mn+1))<<endl;
    return 0;
       }


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
int main(){
	int n, w;
	int a;
	long long t = 0, maxt = 0;
	cin>>n>> w;
	for(int i=0; i<n ;i++) {
		cin>>a;
		t += a;
		if(t>maxt) maxt = t;

	}

	int ans = 0;

	if(w>maxt){
		ans = w-maxt;
		if(maxt > 0) ans++;
	}

	cout<<ans;

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
int main(){
	int n, w;
	int a;
	long long t = 0, maxt = 0, mint=0;
	cin>>n>> w;
	for(int i=0; i<n ;i++) {
		cin>>a;
		t += a;
		if(t>maxt) maxt = t;
		if(t<mint) mint = t;

	}

	long long ans = 0;

	if(w>=maxt){
		ans = w-maxt+1+mint;
//		if(maxt > 0) ans++;
	}

	cout<<ans;

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
int main(){
	int n, w;
	int a;
	long long t = 0, maxt = 0;
	cin>>n>> w;
	for(int i=0; i<n ;i++) {
		cin>>a;
		t += a;
		if(t>maxt) maxt = t;

	}

	int ans = 0;

	if(w>maxt) ans = w-maxt;

	if(maxt != 0) ans++;

	cout<<ans;

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
int main(){
	int n, w;
	int a;
	long long t = 0, maxt = 0;
	cin>>n>> w;
	for(int i=0; i<n ;i++) {
		cin>>a;
		t += a;
		if(t>maxt) maxt = t;

	}

	long long ans = 0;

	if(w>=maxt){
		ans = w-maxt;
		if(maxt > 0) ans++;
	}

	cout<<ans;

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
int main(){
	int n, w;
	int a;
	long long t = 0, maxt = 0;
	cin>>n>> w;
	for(int i=0; i<n ;i++) {
		cin>>a;
		t += a;
		if(t>maxt) maxt = t;

	}

	int ans = 0;

	if(w>maxt){
		ans = w-maxt;
		if(maxt != 0) ans++;
	}

	cout<<ans;

	return 0;
}