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

//
//package cf_educational_33;
//
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        // TODO code application logic here
        ProblemD solver;
//        try{
//                File f = new File("src/cf_educational_33/input.txt");
//                solver = new ProblemD( new FileInputStream(f),System.out);
//        }catch(FileNotFoundException ex){
                solver = new ProblemD( System.in,System.out);                           
//        }
        
        solver.solve();
    }
    
    
}

class ProblemD{
    private final Scanner scanner;
    private final PrintStream output;
    public ProblemD(InputStream input,PrintStream output){
        this.scanner = new Scanner(input);
        this.output=output;
    }
    long maxToAdd[];
    long acumSum[];
    long d;
    int a[];
    int n;
    public void solve(){
        n = scanner.nextInt();
        d = scanner.nextInt();
        a = new int[n];
        maxToAdd = new long[n];
        acumSum = new long[n];
        for(int i = 0;i < n ; i++){
            a[i]=scanner.nextInt();
        }
        
        acumSum[0] = a[0];
        for(int i = 1;i < n ; i++){
            acumSum[i] = acumSum[i-1] + a[i];
        }
        maxToAdd[n-1] = Math.max(0,d-acumSum[n-1]);
        for(int i = n-2; i>=0; i--){
            long mHere = Math.max(0,d-acumSum[i]);
            long mNext = maxToAdd[i+1];
            maxToAdd[i] = Math.max(0,Math.min(mHere, mNext));
        }
//        for(int i = 0;i < n ; i++){
//            System.out.println("maxToAdd["+i+"] = "+maxToAdd[i]);
//        }
        long currentlyAdded = 0;
        int numDays = 0;
        boolean answerExists = true;
         for(int i = 0;i < n ; i++){
            if(a[i]==0){
                long currentAccount = currentlyAdded+acumSum[i];
                if(currentAccount<0){
                    numDays++;
                    if(-currentAccount <= maxToAdd[i]){
                        currentlyAdded=maxToAdd[i];
                    }else{
                        answerExists = false;
                    }
                }
            }else{
                if((currentlyAdded+acumSum[i])>d){
                    answerExists=false;
                }
            }
        }
         if(answerExists){
             output.println(numDays);
         }else{
             output.println("-1");
         }
        
        
    }
}
    
class ProblemC{
    private final Scanner scanner;
    private final PrintStream output;
    public ProblemC(InputStream input,PrintStream output){
        this.scanner = new Scanner(input);
        this.output=output;
    }
    List<List<Integer>> G;
    int cost[];
    boolean visited[];
    
    public void solve(){
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        G = new ArrayList<>();
        for(int i = 0; i<n; i++){
            G.add(new ArrayList<Integer>());
        }
        cost = new int[n];
        for(int i = 0; i<n; i++){
          cost[i] = scanner.nextInt();
        }
        for(int i = 0; i<m; i++){
          int x = scanner.nextInt()-1;
          int y = scanner.nextInt()-1;
          G.get(x).add(y);
          G.get(y).add(x);
        }
        visited=new boolean[n];
        Arrays.fill(visited, false);
        long minValue = 0;
        for(int i = 0; i<n; i++){
          if(!visited[i]){
              long minLocalValue = Integer.MAX_VALUE;
              Queue<Integer> Q = new ArrayDeque<>();
              
              Q.add(i);
              visited[i]=true;
              while(!Q.isEmpty()){
                  int x = Q.poll();
                  if(minLocalValue > cost[x]){
                      minLocalValue = cost[x];
                  }
                  G.get(x).stream().filter( v -> !visited[v]).forEach(v -> {visited[v] = true; Q.add(v);});
                  
              }
              minValue+=minLocalValue;
          }
        }
        output.println(minValue);
    }
    
}
class ProblemB{
    private final Scanner scanner;
    private final PrintStream output;
    public ProblemB(InputStream input,PrintStream output){
        this.scanner = new Scanner(input);
        this.output=output;
    }
    private boolean[] isBeautiful;
    public void solve(){
        isBeautiful=new boolean[1000000];
        for(int i = 0; i< isBeautiful.length; i++){
            isBeautiful[i]=false;
        }
        int current=1;
        int n = 0;
        while((current<<n) < isBeautiful.length){
            isBeautiful[current<<n]=true;
            current = (current<<1) + 1;
            n++;
        }
        
        int value = scanner.nextInt();
        int answer = 1;
        for(int i = 1; i<=value; i++){
            if(value%i==0 && isBeautiful[i]){
                answer= Math.max(i, answer);
            }
        }
        output.println(answer);
    }
    
}

class ProblemA{
    private final Scanner scanner;
    private final PrintStream output;
    public ProblemA(InputStream input,PrintStream output){
        this.scanner = new Scanner(input);
        this.output=output;
    }
    public void solve(){
        int numGames = scanner.nextInt();
        int p1 = 1;
        int p2 = 2;
        int ex = 3;
        boolean possible = true;
        while(numGames-- > 0){
            int winner = scanner.nextInt();
            if(winner == p1 || winner == p2){
                p1 = winner;
                p2 = ex;
                ex = 1+2+3-p1-p2;
            }else{
                possible = false;
            }
        }
        if(possible){
            output.println("YES");
        }else{
            output.println("NO");
        }
    }
}
