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;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int MAX_N = 1e5 + 5;
int n;
long long d;
long long a[MAX_N], rec[MAX_N];
long long add[MAX_N << 2];
long long ma[MAX_N << 2];
void pushUp(int rt) { ma[rt] = max(ma[rt << 1], ma[rt << 1 | 1]); }
void pushDown(int rt) {
  if (add[rt]) {
    add[rt << 1] += add[rt];
    add[rt << 1 | 1] += add[rt];
    ma[rt << 1] += add[rt];
    ma[rt << 1 | 1] += add[rt];
    add[rt] = 0;
  }
}
void build(int l, int r, int rt) {
  add[rt] = 0;
  if (l == r) {
    ma[rt] = rec[l];
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  pushUp(rt);
}
void update(int L, int R, int c, int l, int r, int rt) {
  if (L <= l && r <= R) {
    add[rt] += c;
    ma[rt] += c;
    return;
  }
  pushDown(rt);
  int m = (l + r) >> 1;
  if (L <= m) update(L, R, c, l, m, rt << 1);
  if (m < R) update(L, R, c, m + 1, r, rt << 1 | 1);
  pushUp(rt);
}
long long query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) return ma[rt];
  pushDown(rt);
  int m = (l + r) >> 1;
  long long ret = -0x7fffffff;
  if (L <= m) ret = max(ret, query(L, R, l, m, rt << 1));
  if (m < R) ret = max(ret, query(L, R, m + 1, r, rt << 1 | 1));
  return ret;
}
int main() {
  scanf("%d%lld", &n, &d);
  for (int i = (1), _end_ = (n + 1); i < _end_; ++i) scanf("%lld", &a[i]);
  for (int i = (1), _end_ = (n + 1); i < _end_; ++i) rec[i] = rec[i - 1] + a[i];
  build(1, n, 1);
  int cnt = 0;
  bool flag = true;
  long long mav = query(1, n, 1, n, 1);
  if (mav > d) flag = false;
  if (flag)
    for (int i = (1), _end_ = (n + 1); i < _end_; ++i) {
      if (a[i] == 0) {
        long long tmp = query(i, i, 1, n, 1);
        if (tmp >= 0) continue;
        cnt++;
        long long mav = query(i, n, 1, n, 1);
        if (mav > d) {
          flag = false;
          break;
        }
        if (tmp + d - mav < 0) {
          flag = false;
          break;
        }
        update(i, n, d - mav, 1, n, 1);
      }
    }
  if (flag) {
    printf("%d\n", cnt);
  } else
    puts("-1");
  return 0;
}
