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

///Fahim Ahmed :: Dhaka Residential Model College
#pragma comment(linker, "/STACK:16777216") ///Increases Stack size
#include <bits/stdtr1c++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//
//using namespace __gnu_pbds;
///// A red-black tree table storing ints and their order
///// statistics. Note that since the tree uses
///// tree_order_statistics_node_update as its update policy, then it
///// includes its methods by_order and order_of_key.
//typedef
//tree<
//  int,
//  null_type,
//  less<int>,
//  rb_tree_tag,
//  // This policy updates nodes' metadata for order statistics.
//  tree_order_statistics_node_update>
//set_t; ///works like set but keeps order
///*
//    extra methods:
//    set_t.find_by_order(order);
//    set_t.order_of_key(key);
//*/
#define li long long int
#define ui unsigned long long int
///I/O functions BEGIN
#define rfile(a) freopen(a, "r", stdin)
#define wfile(a) freopen(a, "w", stdout)
#define rd(a) scanf("%lf", &a)
#define lb printf("\n")
#define ru(n) scanf("%llu",&n)
#define rl(n) scanf("%I64d", &n)
#define ri(n) scanf("%d", &n)
#define rs(n) scanf("%[^\n]",n)
#define rtok(n) scanf("%s",n)
#define MAX_BUFFER_SIZE 200001
#define endl '\n'

///Use printf to output anything
///For string you can also use puts(string.c_str());
///IO functions END
#define pi acos(-1.00)
#define pb push_back
#define mp make_pair
#define Pr printf
#define For(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000003
#define eps 1e-9
#define pii pair<int,int>
template <typename t1> t1 gcd(t1 a, t1 b) {while(b != 0 ){a=a%b;a = a^b;b = b^a;a = a^b;}return a;}
template <typename t1> t1 lcm(t1 a, t1 b) { return a * (b / gcd(a, b)); }
template <typename t1> bool check (t1 i, t1 k){return i&((t1)1<<k);}
template <typename t1> t1 On(t1 i, t1 k) { return i|((t1)1 << k);}
template <typename t1> t1 Off(t1 i, t1 k) {return (i-((check(i,k))<<k) );}

li cumsum[100002];
li arr[100005];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    li n,d;
    cin>>n>>d;
    vector<li> zeroes;
    vector<li> transactions;
    vector<pair<pair<int,int>,li> >balance_heads;
    vector<pair<li,int> > ranker,ranked;
    cumsum[0]=0;
    li current_pot=0;
    int balance_open=1;
    li max_balance=0;
    for(li i=1;i<=n;i++)
    {
        cin>>arr[i];
        cumsum[i]=arr[i]+cumsum[i-1];
        if(cumsum[i] > d)
        {
            cout<<"-1\n";
            //printf("ekhan theke -1 age\n");
            return 0;
        }
        if(arr[i]==0)
        {
            zeroes.pb(i);
        }
//        if(arr[i]<0)
//        {
//            balance_heads.pb(mp(mp(balance_open, (int)i-1),current_pot));
//            current_pot=arr[i];
//            balance_open=(int)i;
//        }
//        else{
//            current_pot+=arr[i];
//        }
        if(arr[i]!=0){
            ranker.pb(mp(cumsum[i],(int)i));
        }
    }

    sort(ranker.begin(), ranker.end(),greater<pair<li,int> >());

//    for(int i=0;i<n;i++)
//    {
//        cout<<ranker[i].first<<" "<<ranker[i].second<<endl;
//    }

    int right_most=0;
    int ranksize=ranker.size();
    int rankedsize=0;
    for(int i=0;i<ranksize;i++)
    {
        if(ranker[i].second > right_most)
        {
            ranked.pb(ranker[i]);
            right_most=ranker[i].second;
            rankedsize++;
        }
    }
    int ctr=0;
    li donate=0;
    int i;
    int zesize=zeroes.size();
    int rank_ptr=0;
    for(i=0;i < zesize; i++)
    {
        li current = zeroes[i];
        while(rank_ptr < rankedsize and ranked[rank_ptr].second < current)
        {
            rank_ptr++;
        }
        if(rank_ptr >= rankedsize)
        {
            if(donate + cumsum[current] < 0)
            {
                donate+=-1*(cumsum[current]+donate);
                ctr++;
            }
            i++;
            break;
        }
        //printf("Check kortesi %d te, donated = %d, ase mot %d\n", (int)current, (int)donate, (int)(donate+ cumsum[current]));
        if(cumsum[current]+donate >= 0)
        {
            continue;
        }
        li diff=d-(ranked[rank_ptr].first + donate);
        if(diff<=0)
        {
            cout<<"-1\n";return 0;
        }
        else if(diff> 0){
            if(diff  + donate + cumsum[current] < 0)
            {
                cout<<"-1\n";
                return 0;
            }
            ctr++;
            donate+=diff;
        }
    }
    for(;i < zesize; i++)
    {
        li current = zeroes[i];
        if(donate + cumsum[current] < 0)
        {
            donate+=-1*(cumsum[current]+donate);
            ctr++;
        }
        break;
    }
    cout<<ctr<<endl;
    return 0;
}
