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;
const int BLACK = 1, WHITE = 2;
int len_of_number(int n) {
  int len(0);
  while (n != 0) {
    ++len;
    n /= 10;
  }
  return len;
}
int sum_of_digits(int n) {
  int sod = 0;
  while (n != 0) {
    sod += (n % 10);
    n /= 10;
  }
  return sod;
}
bool isPalindrome(string str) {
  int n = str.length();
  for (int i = (0); i <= (n / 2); i++)
    if (str[i] != str[n - i - 1]) return false;
  return true;
}
long long int fast_exp(long long int x, long long int i) {
  long long int ans = 1;
  while (i > 0) {
    if (i & 1) ans = (ans * x);
    i >>= 1;
    x = (x * x);
  }
  return ans;
}
long long int fast_exp(long long int x, long long int i, long long int mod) {
  long long int ans = 1;
  while (i > 0) {
    if (i & 1) ans = (ans * x) % mod;
    i >>= 1;
    x = (x * x) % mod;
  }
  return ans;
}
long long int modInverse(long long int x, long long int mod) {
  return fast_exp(x, mod - 2, mod);
}
long long int egcd_x, egcd_y, egcd_d;
void egcd(long long int a, long long int b) {
  if (b == 0) {
    egcd_x = 1, egcd_y = 0;
    egcd_d = a;
    return;
  }
  egcd(b, a % b);
  long long int temp = egcd_x;
  egcd_x = egcd_y;
  egcd_y = temp - (a / b) * egcd_y;
}
long long int extended_gcd(long long int a, long long int b) {
  if (a >= b) {
    egcd(a, b);
    return ((egcd_x % b) + b) % b;
  } else {
    egcd(b, a);
    return ((egcd_y % b) + b) % b;
  }
}
long long int gcd(long long int x, long long int y) {
  long long int t;
  while (y != 0) {
    t = x % y;
    x = y;
    y = t;
  }
  return x;
}
bool isPrime(int n) {
  int root = sqrt(n);
  for (int i = (2); i <= (root); i++)
    if (n % i == 0) return 0;
  return 1;
}
vector<int> cnt;
string groupAndCnt(string str) {
  string a = "";
  int prev_count = 0;
  char prev_char = '~';
  for (auto &c : str) {
    if (c != prev_char) {
      if (prev_count) {
        a += prev_char;
        cnt.push_back(prev_count);
      }
      prev_count = 1;
      prev_char = c;
    } else
      ++prev_count;
  }
  cnt.push_back(prev_count);
  a += prev_char;
  return a;
}
vector<int> pset, sz;
void init_disjoint_set(int N) {
  pset.resize(N);
  sz.resize(N);
  for (int i = (0); i <= (N - 1); i++) pset[i] = i, sz[i] = 1;
}
int findSet(int i) { return (i == pset[i]) ? i : (pset[i] = findSet(i)); }
void unionSet(int i, int j) {
  int p1 = findSet(i);
  int p2 = findSet(j);
  if (p1 == p2)
    sz[p1] += 1;
  else {
    pset[p1] = p2;
    sz[p2] += sz[p1];
  }
}
void solve(int T) {
  long long int n, d;
  cin >> n >> d;
  vector<long long int> a(n);
  for (auto &x : a) cin >> x;
  long long int bal = 0;
  for (int i = (0); i <= (n - 1); i++) {
    bal += a[i];
    if (bal > d) {
      cout << -1;
      return;
    }
  }
  bal = 0;
  long long int ans = 0;
  for (int i = (0); i <= (n - 1); i++) {
    if (a[i] == 0) {
      if (bal >= 0) {
      } else {
        long long int MIN = numeric_limits<long long int>::max();
        long long int SUM = 0;
        for (int j = (i + 1); j <= (n - 1); j++) {
          if (a[j] == 0) break;
          SUM += a[j];
          MIN = min(MIN, d - SUM);
        }
        if (MIN == numeric_limits<long long int>::max()) {
          ++ans;
          bal = 0;
        } else {
          if (MIN == 0) {
            bal = 0;
            ++ans;
          } else if (MIN < 0) {
            cout << -1;
            return;
          } else {
            ++ans;
            bal = min(MIN, d);
          }
        }
      }
    } else
      bal += a[i];
  }
  if (bal > d) {
    cout << -1;
    return;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int test_cases;
  test_cases = 1;
  for (int T = (0); T <= (test_cases - 1); T++) {
    solve(T);
  }
  return 0;
}
