9 13
6 14 19 5 -5 6 -10 20 8
 8 9
6 -1 5 -5 -8 -7 -8 -7
 10 7
-9 3 -4 -22 4 -17 0 -14 3 -2
 6 2
-2 3 0 -2 0 0
 5 10
-8 -24 0 -22 12
 5 13756
-2 -9 -10 0 10
 7 3
1 -3 0 3 -1 0 2
 9 9
-3 2 0 -2 -7 -1 0 5 3
 2 3
2 0
 19 78701
1 0 -1 0 -1 -1 0 1 0 -1 1 1 -1 1 0 0 -1 0 0
 5 4
-1 0 0 1 -1
 6 4
-1 0 2 -4 0 5
 20 23036
-1 1 -1 -1 -1 -1 1 -1 -1 0 0 1 1 0 0 1 0 0 -1 -1
 5 4
-1 0 -3 0 3
 12 82016
1 -2 -1 -1 -2 -1 0 -2 -1 1 -2 2
 7 4
-6 0 2 -3 0 4 0
 4 4
2 2 0 1
 6 1
-3 0 0 0 -2 3
 8 26
-4 9 -14 -11 0 7 23 -15
 20 23079
0 1 1 -1 1 0 -1 -1 0 0 1 -1 1 1 1 0 0 1 0 1
 1 1
1
 7 8555
-2 -3 -2 3 0 -2 0
 4 100
-100 0 -50 100
 3 14
12 12 -8
 1 1
2
 10 23
9 7 14 16 -13 -22 24 -3 -12 14
 8 11
12 -12 -9 3 -22 -21 1 3
 19 49926
-2 0 2 0 0 -2 2 -1 -1 0 0 0 1 0 1 1 -2 2 2
 16 76798
-1 11 -7 -4 0 -11 -12 3 0 -7 6 -4 8 6 5 -10
 9 5
-2 0 3 -4 0 4 -3 -2 0

-1
 -1
 1
 1
 1
 1
 -1
 2
 0
 1
 1
 -1
 1
 1
 1
 1
 -1
 1
 -1
 0
 0
 1
 1
 -1
 -1
 -1
 -1
 1
 1
 1

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;

typedef long long ll;

typedef long double ldb;

typedef pair<ll,ll> pll;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



#define ff first

#define ss second

#define pb push_back

#define mp make_pair

#define V vector

#define endl "\n"

#define CLEAR(a) memset(a,0,sizeof(a))

#define all(x) x.begin(),x.end()

#define sz(x) ((ll)x.size())

#define rep0(i,n) for(ll i=0;i<n;i++)

#define rep1(i,n) for(ll i=1;i<=n;i++)

#define per(i,a,b) for(ll i=a;i>=b;i--)

#define ios_tie() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(nullptr)

#define trace1(a)             cout <<#a<<":"<<a<< endl;

#define trace2(a,b)           cout <<#a<<":"<<a<<" | "<<#b<<":"<<b<< endl;

#define trace3(a,b,c)         cout <<#a<<":"<<a<<" | "<<#b<<":"<<b<<" | "<<#c<<":"<<c<<endl;

#define trace4(a,b,c,d)       cout <<#a<<":"<<a<<" | "<<#b<<":"<<b<<" | "<<#c<<":"<<c<<" | "<<#d<<":"<<d<<endl;



const ll inf = LLONG_MAX;

const ll mod = 998244353;

const ll maxn = 1e5+1;

const ldb PI = acos(-1);



void lol(ll s) {cerr<<"check........................................... "<<s<<endl;}

ll power(ll x,ll y) {ll res=1; x%=mod; while(y) {if(y&1) res=(res*x)%mod; y>>=1LL; x=(x*x)%mod; }return res;}

ll inv(ll x) {return power(x,mod-2);}//(1/x)%y = x^(y-2) % y;	// pow(x,y)%m = pow(x,y%(m-1))%m

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll gcd(ll a, ll b) {while(b) b ^= a ^= b ^= a %= b; return a;}



int main()

{

    ios_tie();

    ll n,d;
    cin>>n>>d;
    ll a[n];
    rep0(i,n)
    	cin>>a[i];
    ll cnt = 0, sum = 0;
    rep0(i,n)
    {
    	sum += a[i];
    	if(sum>d)
    		return cout<<"-1\n",0;
    	if(a[i]==0&&sum<0)
    			cnt++,sum=0;
    }
    cout<<cnt<<endl;

    return 0;

}