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;
struct A {
  int l, r;
  int nxl, nxr;
  int big;
  int add;
} Node[200005];
int all[200005];
int add[200005] = {0};
int now = 1;
void build(int l, int r, int here) {
  Node[here].l = l;
  Node[here].r = r;
  Node[here].add = 0;
  if (l == r) {
    Node[here].big = add[l];
    return;
  }
  Node[here].nxl = now++;
  Node[here].nxr = now++;
  build(l, (l + r) / 2, Node[here].nxl);
  build((l + r) / 2 + 1, r, Node[here].nxr);
  Node[here].big = max(Node[Node[here].nxl].big, Node[Node[here].nxr].big);
}
void UPD(int here) {
  Node[Node[here].nxl].big += Node[here].add;
  Node[Node[here].nxr].big += Node[here].add;
  Node[Node[here].nxl].add += Node[here].add;
  Node[Node[here].nxr].add += Node[here].add;
  Node[here].add = 0;
}
int Find(int l, int r, int here) {
  if (l == Node[here].l && r == Node[here].r) return Node[here].big;
  UPD(here);
  if (r <= (Node[here].l + Node[here].r) / 2)
    return Find(l, r, Node[here].nxl);
  else if (l > (Node[here].l + Node[here].r) / 2)
    return Find(l, r, Node[here].nxr);
  else
    return max(Find(l, (Node[here].l + Node[here].r) / 2, Node[here].nxl),
               Find((Node[here].l + Node[here].r) / 2 + 1, r, Node[here].nxr));
}
void Add(int l, int r, int here, int con) {
  if (l == Node[here].l && r == Node[here].r) {
    Node[here].add += con;
    Node[here].big += con;
    return;
  }
  UPD(here);
  if (r <= (Node[here].l + Node[here].r) / 2)
    Add(l, r, Node[here].nxl, con);
  else if (l > (Node[here].l + Node[here].r) / 2)
    Add(l, r, Node[here].nxr, con);
  else {
    Add(l, (Node[here].l + Node[here].r) / 2, Node[here].nxl, con);
    Add((Node[here].l + Node[here].r) / 2 + 1, r, Node[here].nxr, con);
  }
  Node[here].big = max(Node[Node[here].nxl].big, Node[Node[here].nxr].big);
}
int main() {
  int N, D, ok = 1, last = -1, i, ans = 0;
  scanf("%d %d", &N, &D);
  for (i = 1; i <= N; i++) {
    scanf("%d", &all[i]);
    add[i] = add[i - 1] + all[i];
  }
  build(0, N, 0);
  for (i = 1; i <= N; i++) {
    if (all[i] == 0) {
      if (Find(i, i, 0) >= 0) continue;
      if (last == -1 || Find(last, N, 0) + (0 - Find(i, i, 0)) > D) {
        if (Find(i, N, 0) + (0 - Find(i, i, 0)) > D)
          ok = 0;
        else {
          Add(i, N, 0, (0 - Find(i, i, 0)));
          last = i;
          ans++;
        }
      } else
        Add(last, N, 0, (0 - Find(i, i, 0)));
    }
  }
  if (!ok)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
