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

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.util.Arrays.copyOf;
import static java.util.Arrays.fill;
import static java.util.Arrays.sort;
import static java.util.Collections.reverseOrder;
import static java.util.Collections.shuffle;
import static java.util.Collections.sort;

public class Main {
    private FastScanner in;
    private PrintWriter out;

    private void solve() throws IOException {
        int n = in.nextInt();
        long d = in.nextLong();
        long[] a = new long[n];
        ArrayList<Integer> zero = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
            if (a[i] == 0)
                zero.add(i);
        }
        long[] v = new long[n];
        long max = Long.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            v[i] = (i > 0 ? v[i - 1] : 0) + a[i];
            max = max(max, v[i]);
        }
        if (max > d) {
            out.println(-1);
            return;
        }

        long min = Long.MAX_VALUE;
        for (int i : zero)
            min = min(min, v[i]);

        long ans = 0;
        if (min < 0) {

            long[] maxAdd = new long[zero.size()];

            for (int i = 0; i < maxAdd.length; i++) {
                long cur = Long.MAX_VALUE;
                for (int j = zero.get(i); j < (i + 1 < zero.size() ? zero.get(i + 1) : n); j++) {
                    cur = min(cur, d - v[j]);
                }
                maxAdd[i] = cur;
            }

            for (int i = maxAdd.length - 2; i >= 0; i--)
                maxAdd[i] = min(maxAdd[i], maxAdd[i + 1]);

            long[] need = new long[zero.size()];
            for (int i = 0; i < zero.size(); i++)
                need[i] = max(0, -v[zero.get(i)]);

            for (int i = 1; i < need.length; i++) {
                need[i] = max(need[i], need[i - 1]);
            }

            boolean ok = true;
            for (int i = 0; i < zero.size(); i++) {
                ok &= maxAdd[i] >= need[i];
            }

            if (!ok) {
                out.println(-1);
                return;
            }

            long add = 0;
            for (int i = 0; i < zero.size(); i++) {
                if (need[i] > 0 && add < need[i]) {
                    add = maxAdd[i];
                    ans++;
                }
            }
        }
        out.println(ans);
    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

        boolean hasNextLine() throws IOException {
            return br.ready();
        }

    }

    private void run() throws IOException {
        in = new FastScanner(System.in);
        // in = new FastScanner(new FileInputStream(".in"));
        out = new PrintWriter(System.out);
        // out = new PrintWriter(new FileOutputStream(".out"));

        solve();

        out.flush();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}