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

#include <bits/stdc++.h>
using namespace std;
int maxarr(vector<int> &arr);
int minarr(vector<int> &arr);
long long modulo(long long base, long long exponent, long long modulus);
long long choose(long long n, long long k);
bool isprime(long long n);
long long inverse(long long a, long long m);
long long fastmult(long long a, long long b, long long c);
vector<long long> a(1000010);
vector<long long> prime;
long long sum[1000010];
vector<bool> aprime(1000010);
void setprime();
long long divCeil(long long a, long long b);
long long arrceil(vector<long long> a, long long k);
int main() {
  long long n, d;
  cin >> n >> d;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  ;
  long long bal = 0;
  long long ans = 0;
  vector<long long> dp(n, 0);
  long long sum = 0;
  long long maxi = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      long long j = i;
      i++;
      sum = 0;
      maxi = 0;
      while (a[i] != 0 && i < n) {
        sum += a[i];
        maxi = max(sum, maxi);
        dp[i] = maxi;
        i++;
      }
      dp[j] = maxi;
      if (i == n) break;
      i--;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      if (bal < 0) {
        ans++;
      }
      long long temp = min(d, d - dp[i]);
      bal = max(temp, (long long)0);
      continue;
    }
    bal += a[i];
    if (bal > d) {
      cout << -1;
      return 0;
    }
  }
  cout << ans;
  return 0;
}
int maxarr(vector<int> &arr) {
  int maxi = INT_MIN;
  for (int i = 0; i < arr.size(); i++) maxi = max(arr[i], maxi);
  return maxi;
}
int minarr(vector<int> &arr) {
  int mini = INT_MAX;
  for (int i = 0; i < arr.size(); i++) mini = min(arr[i], mini);
  return mini;
}
long long modulo(long long base, long long exponent, long long modulus) {
  if (modulus == 1) return 0;
  long long result = 1;
  base = base % modulus;
  while (exponent > 0) {
    if (exponent % 2 == 1) {
      result = (result * base) % modulus;
    }
    exponent = exponent >> 1;
    base = (base * base) % modulus;
  }
  return result;
}
long long choose(long long n, long long k) {
  if (k == 0) return 1;
  return (n * choose(n - 1, k - 1)) / k;
}
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
void EE(long long a, long long b, long long &co1, long long &co2) {
  if (a % b == 0) {
    co1 = 0;
    co2 = 1;
    return;
  }
  EE(b, a % b, co1, co2);
  long long temp = co1;
  co1 = co2;
  co2 = temp - co2 * (a / b);
}
long long inverse(long long a, long long m) {
  long long x, y;
  EE(a, m, x, y);
  if (x < 0) x += m;
  return x;
}
long long fastmult(long long a, long long b, long long c) {
  if (b == 0) return 0;
  long long res = fastmult(a, b >> 1, c);
  res = (res + res) % c;
  if (b % 2 == 1) {
    res = (res + a) % c;
  }
  return res;
}
void setprime() {
  aprime[0] = true;
  for (int i = 2; i * i <= 1000010; i++) {
    if (aprime[i - 1] == false) {
      for (int j = i * 2; j <= 1000010; j += i) {
        aprime[j - 1] = true;
      }
    }
  }
}
long long divCeil(long long a, long long b) { return (a + b - 1) / b; }
long long arrceil(vector<long long> a, long long k) {
  long long n = a.size();
  long long low = 0;
  long long high = n - 1;
  if (a[0] > k) return -1;
  while (low < high) {
    long long mid = (low + high + 1) / 2;
    if (a[mid] <= k)
      low = mid;
    else
      high = mid - 1;
  }
  return low;
}
