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.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class EduD implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            String filename = "";
            if (filename.isEmpty()) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader(filename + ".in"));
                out = new PrintWriter(filename + ".out");
            }
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), " :");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    <T> ArrayDeque<T>[] createGraphDeque(int size) {
        ArrayDeque<T>[] list = new ArrayDeque[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayDeque<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new EduD().run();
//        new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    int[] log;

    class Sparse {
        int[][] data;

        Sparse(int[] d) {
            int k = 0;
            while ((1 << k) < d.length) {
                k++;
            }
            k++;
            data = new int[k][d.length];
            for (int i = 0; i < d.length; i++) {
                data[0][i] = d[i];
            }
            for (int level = 1; level < k; level++) {
                for (int start = 0; start < d.length; start++) {
                    int next = start + (1 << (level - 1));
                    if (next >= d.length) break;

                    data[level][start] = Math.max(data[level - 1][start], data[level - 1][next]);
                }
            }
        }

        int get(int l, int r) {
            int k = log[r - l];
            int a = data[k][l];
            int b = data[k][r - (1 << k) + 1];
            return Math.max(a, b);
        }
    }

    List<Integer>[] layersList;
    int[][] layers;
    List<Integer>[] g;
    int[] a;
    int[] tin;
    int[] tout;
    int[] height;
    int[] indexOnLayer;
    int timer;

    void dfs(int v, int p, int h) {
        tin[v] = timer++;
        height[v] = h;
        layersList[h].add(v);
        indexOnLayer[v] = layersList[h].size() - 1;
        for (int y : g[v]) {
            if (y == p) continue;
            dfs(y, v, h + 1);
        }
        tout[v] = timer++;
    }

    int findLeftIndex(int v, int k) {
        int targetH = height[v] + k;
        if (targetH >= layers.length) return Integer.MAX_VALUE;
        int l = 0;
        int r = layers[targetH].length - 1;

        int ans = Integer.MAX_VALUE;
        while (l <= r) {
            int mid = (l + r) >> 1;
            int vert = layers[targetH][mid];
            if (tin[vert] >= tin[v] && tout[vert] <= tout[v]) {
                //parent
                ans = mid;
                r = mid - 1;
            } else if (tout[vert] < tin[v]) {
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        return ans;
    }

    int findRightIndex(int v, int k) {
        int targetH = height[v] + k;
        if (targetH >= layers.length) return Integer.MIN_VALUE;
        int l = 0;
        int r = layers[targetH].length - 1;

        int ans = Integer.MIN_VALUE;
        while (l <= r) {
            int mid = (l + r) >> 1;
            int vert = layers[targetH][mid];
            if (tin[vert] >= tin[v] && tout[vert] <= tout[v]) {
                //parent
                ans = mid;
                l = mid + 1;
            } else if (tout[vert] < tin[v]) {
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        return ans;
    }

    void solve() throws IOException {
        int n = readInt();
        int d = readInt();
        long[] values = new long[n];
        int[] a = readIntArray(n);
        long cur = 0;
        for (int i = 0; i < n; i++) {
            cur += a[i];
            values[i] = cur;
        }

        long[] maxOnSuf = new long[n];
        for (int i = n - 1; i >= 0; i--) {
            maxOnSuf[i] = values[i];
            if (i + 1 < n) {
                maxOnSuf[i] = Math.max(maxOnSuf[i], maxOnSuf[i + 1]);
            }
        }

        int answer = 0;
        if (maxOnSuf[0] > d) {
            out.println(-1);
            return;
        }

        long added = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == 0) {
                long now = values[i] + added;
                if (now < 0) {

                    long todayMaxOnSuf = maxOnSuf[i] + added;
                    long canAdd = d - todayMaxOnSuf;

                    if (now + canAdd < 0) {
                        out.println(-1);
                        return;
                    }
                    answer++;
                    added += canAdd;
                }
            }
        }
        out.println(answer);
    }


}