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.*;
import java.util.Map.Entry;
import java.lang.Math;
import java.math.BigInteger;

public class Problem {
	long INF = Long.MAX_VALUE - 12345;
	int MODULO = 1000 * 1000 * 1000 + 2346;
	void solve() throws IOException {
		int n = rI();
		int d = rI();
		ArrayList<Integer> list = new ArrayList<>();
		long[] a = new long[n+1];
		for(int i=1;i<=n;++i){
			a[i] = rI();
			if(a[i]==0){
				list.add(i);
			}
		}
		
		long[] prefSum = new long[n+1];
		prefSum[0] = 0;
		
		for(int i=1;i<=n;++i){
			prefSum[i] = prefSum[i-1] + a[i];
			if(prefSum[i]>d){
				out.println(-1);
				return;
			}
		}
		
		int ans = 0;
		long plus = 0;
		
		long[] suffMax = new long[n+2];
		suffMax[n] = prefSum[n];
		suffMax[n+1] = -INF;
		for(int i=n-1;i>=0;--i){
			suffMax[i] = Math.max(suffMax[i+1], prefSum[i]);
		}
		
		for(int checkDay: list){
			if(prefSum[checkDay] + plus<0){
				long max = d - suffMax[checkDay+1] - plus;
				plus += max;
				ans++;
			}
			if(prefSum[checkDay] + plus<0){
				out.println(-1);
				return;
			}
		}
		out.println(ans);
	}
	

	class SegmentTree {
		long[] tMax;
		long[] tSum;
		SegmentTree(long[] a, int n) {
			tMax = new long[n * 4];
			buildMax(a, 1, 1, n);
			buildSum(a, 1, 1, n);
		}

		void buildMax(long[] a, int v, int tl, int tr) {
			if (tl == tr) {
				tMax[v] = a[tl];
				return;
			}
			int tm = (tr + tl) / 2;
			buildMax(a, 2 * v, tl, tm);
			buildMax(a, 2 * v + 1, tm + 1, tr);
			tMax[v] = Math.max(tMax[2 * v], tMax[2 * v + 1]);
		}
		
		void buildSum(long[] a, int v, int tl, int tr) {
			if (tl == tr) {
				tSum[v] = a[tl];
				return;
			}
			int tm = (tr + tl) / 2;
			buildSum(a, 2 * v, tl, tm);
			buildSum(a, 2 * v + 1, tm + 1, tr);
			tSum[v] = tSum[2 * v] + tSum[2 * v + 1];
		}
		
		void updateMax(int v, int tl, int tr, int pos, long value) {
			if (tl == tr) {
				tMax[v] = value;
				return;
			}
			int tm = (tl + tr) / 2;
			if (pos <= tm) {
				updateMax(2 * v, tl, tm, pos, value);
			} else {
				updateMax(2 * v + 1, tm + 1, tr, pos, value);
			}
			tMax[v] = Math.max(tMax[2 * v], tMax[2 * v + 1]);
		}
		
		void updateSum(int v, int tl, int tr, int pos, long value) {
			if (tl == tr) {
				tSum[v] = value;
				return;
			}
			int tm = (tl + tr) / 2;
			if (pos <= tm) {
				updateSum(2 * v, tl, tm, pos, value);
			} else {
				updateSum(2 * v + 1, tm + 1, tr, pos, value);
			}
			tSum[v] = tSum[2 * v] + tSum[2 * v + 1];
		}
		
		long getMax(int v, int tl, int tr, int l, int r) {
			if (l > r) {
				return -INF;
			}
			if (tl == l && tr == r) {
				return tMax[v];
			}
			int tm = (tr + tl) / 2;
			long max1 = getMax(2 * v, tl, tm, l, Math.min(r, tm));
			long max2 = getMax(2 * v + 1, tm + 1, tr, Math.max(l, tm + 1), r);
			return Math.max(max1, max2);
		}
		
		long getSum(int v, int tl, int tr, int l, int r) {
			if (l > r) {
				return 0;
			}
			if (tl == l && tr == r) {
				return tSum[v];
			}
			int tm = (tr + tl) / 2;
			long s1 = getSum(2 * v, tl, tm, l, Math.min(r, tm));
			long s2 = getSum(2 * v + 1, tm + 1, tr, Math.max(l, tm + 1), r);
			return s1 + s2;
		}
	}

	int checkBit(int mask, int bit) {
		return (mask >> bit) & 1;
	}

	public static void main(String[] args) throws IOException {

		new Problem().run();
	}

	boolean isLower(char a) {
		return ((int) a) >= 97 ? true : false;
	}

	int[][] STEPS = { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 } };

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;
	Random rnd = new Random();
	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	Problem() throws FileNotFoundException {

		try {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		} catch (Exception e) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}

		tok = new StringTokenizer("");
	}

	long checkBit(long mask, int bit) {
		return (mask >> bit) & 1;
	}

	// ======================================================

	// ======================================================
	void run() throws IOException {
		solve();
		out.close();
	}

	char[] reverseCharArray(char[] arr) {
		char[] ans = new char[arr.length];
		for (int i = 0; i < arr.length; ++i) {
			ans[i] = arr[arr.length - i - 1];
		}
		return ans;
	}

	int sqrt(double m) {
		int l = 0;
		int r = 1000000000 + 9;
		int i = 1000;
		while (r - l > 1) {
			int mid = (r + l) / 2;
			if (mid * mid > m) {
				r = mid;
			} else {
				l = mid;
			}
		}
		return l;
	}

	int countPow(int m, int n) {
		int ans = 0;
		while (m % n == 0 && m > 0) {
			ans++;
			m /= n;
		}
		return ans;
	}

	long binPow(long a, long b, long m) {
		if (b == 0) {
			return 1;
		}
		if (b % 2 == 1) {
			return ((a % m) * (binPow(a, b - 1, m) % m)) % m;
		} else {
			long c = binPow(a, b / 2, m);
			return (c * c) % m;
		}

	}

	int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	long pow(long x, long k) {
		long ans = 1;
		for (int i = 0; i < k; ++i) {
			ans *= x;
		}
		return ans;
	}

	class Fenwik {

	}

	// ////////////////////////////////////////////////////////////////////

	String delimiter = " ";

	String readLine() throws IOException {
		return in.readLine();
	}

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	double rD() throws IOException {
		return Double.parseDouble(rS());
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int[] readSortedIntArray(int size) throws IOException {
		Integer[] array = new Integer[size];

		for (int index = 0; index < size; ++index) {
			array[index] = rI();
		}
		Arrays.sort(array);

		int[] sortedArray = new int[size];
		for (int index = 0; index < size; ++index) {
			sortedArray[index] = array[index];
		}

		return sortedArray;
	}

	int[] sortedIntArray(int size, int[] array) throws IOException {
		for (int index = 0; index < size; ++index) {
			array[index] = rI();
		}
		Arrays.sort(array);

		int[] sortedArray = new int[size];
		for (int index = 0; index < size; ++index) {
			sortedArray[index] = array[index];
		}

		return sortedArray;
	}
}