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

/*
 * Remember a 7.0 student can know more than a 9.8 student.
 * Grades don't determine intelligence, they test obedience. 
 * I Never Give Up.
 */
import java.util.*;
import java.io.*;
import java.util.Comparator.*;
 
import static java.lang.System.out;
import static java.util.Arrays.sort;
import static java.lang.Math.pow;
//import static java.lang.Math.sqrt;
//import static java.lang.Math.ceil;
//import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.Math.max;
//import static java.lang.Math.floor;
public class ContestMain {
	private static long MOD=1000000007;//10^9+7 
	private static final int N=(int)200005;
//	private static ArrayList<Integer> v[]=new ArrayList[N];
//	private static long color[]=new long[2]; //For Graph Coloring
//	private static boolean mark[]=new boolean [N];
//	static int choice=Integer.MAX_VALUE,trav=Integer.MAX_VALUE;
//	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//	public static void dfs(int node){mark[node]=true;for(int x:v[node]){if(!mark[x]){dfs(x);}}}
	static Reader in=new Reader();
	public static void solve(long ar[],int n,long d){
		long maxv=Long.MIN_VALUE,curr=0;
		int cnt=0;
		int i=0,ind=0;
		LinkedList<Integer> ll=new LinkedList();
		long dept[]=new long[n];
		for(i=0;i<n;i++){
			if(ar[i]>maxv)maxv=ar[i];
			if(ar[i]==0&&curr<0){
				if(ll.isEmpty()){
					ll.add(i);
					curr=0;
					cnt++;
				}
				else if(dept[ll.peek()]+(-curr)<=d&&-curr+maxv<=d){
					dept[ll.peek()]+=-curr;
					curr=0;
				}
				else{
					ll.addFirst(i);
					curr=0;
					maxv=Long.MIN_VALUE;
					cnt++;
				}
			}
			else{
				curr+=ar[i];
				if(curr>d)break;
			}
		}
		if(i<n)out.println(-1);
		else out.println(cnt);
	}
	
	public static void main(String[] args) throws IOException{
		int n=in.nextInt();
		long d=in.nextLong();
		long ar[]=new long[n];
		for(int i=0;i<n;i++)
			ar[i]=in.nextLong();
		solve(ar,n,d);
	}
	static class Reader{
        BufferedReader br;
        StringTokenizer st;
 
        public Reader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
} 