Recenlty Luba got a credit card and started to use it. Let's consider *n* consecutive days Luba uses the card.

She starts with 0 money on her account.

In the evening of *i*-th day a transaction *a*<sub class="lower-index">*i*</sub> occurs. If *a*<sub class="lower-index">*i*</sub> &gt; 0, then *a*<sub class="lower-index">*i*</sub> bourles are deposited to Luba's account. If *a*<sub class="lower-index">*i*</sub> &lt; 0, then *a*<sub class="lower-index">*i*</sub> bourles are withdrawn. And if *a*<sub class="lower-index">*i*</sub> = 0, then the amount of money on Luba's account is checked.

In the morning of any of *n* days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed *d*.

It can happen that the amount of money goes greater than *d* by some transaction in the evening. In this case answer will be «-1».

Luba must not exceed this limit, and also she wants that every day her account is checked (the days when *a*<sub class="lower-index">*i*</sub> = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
The first line contains two integers *n*, *d* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>, 1 ≤ *d* ≤ 10<sup class="upper-index">9</sup>) —the number of days and the money limitation.

The second line contains *n* integer numbers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ... *a*<sub class="lower-index">*n*</sub> ( - 10<sup class="upper-index">4</sup> ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">4</sup>), where *a*<sub class="lower-index">*i*</sub> represents the transaction in *i*-th day.
none
5 10
-1 5 0 -5 3
0
3 4
-10 0 20
-1
5 10
-5 0 10 -11 0
2
5 13756
-2 -9 -10 0 10
1
20 23036
-1 1 -1 -1 -1 -1 1 -1 -1 0 0 1 1 0 0 1 0 0 -1 -1
1
12 82016
1 -2 -1 -1 -2 -1 0 -2 -1 1 -2 2
1
7 8555
-2 -3 -2 3 0 -2 0
1
16 76798
-1 11 -7 -4 0 -11 -12 3 0 -7 6 -4 8 6 5 -10
1
20 23079
0 1 1 -1 1 0 -1 -1 0 0 1 -1 1 1 1 0 0 1 0 1
0
19 49926
-2 0 2 0 0 -2 2 -1 -1 0 0 0 1 0 1 1 -2 2 2
1
19 78701
1 0 -1 0 -1 -1 0 1 0 -1 1 1 -1 1 0 0 -1 0 0
1
10 7
-9 3 -4 -22 4 -17 0 -14 3 -2
1
9 13
6 14 19 5 -5 6 -10 20 8
-1
8 11
12 -12 -9 3 -22 -21 1 3
-1
8 26
-4 9 -14 -11 0 7 23 -15
-1
5 10
-8 -24 0 -22 12
1
10 23
9 7 14 16 -13 -22 24 -3 -12 14
-1
8 9
6 -1 5 -5 -8 -7 -8 -7
-1
3 14
12 12 -8
-1
9 9
-3 2 0 -2 -7 -1 0 5 3
2
4 100
-100 0 -50 100
1
9 5
-2 0 3 -4 0 4 -3 -2 0
1
7 4
-6 0 2 -3 0 4 0
1
6 2
-2 3 0 -2 0 0
1
1 1
2
-1
5 4
-1 0 -3 0 3
1
7 3
1 -3 0 3 -1 0 2
-1
4 4
2 2 0 1
-1
6 1
-3 0 0 0 -2 3
1
1 1
1
0
2 3
2 0
0
5 4
-1 0 0 1 -1
1
6 4
-1 0 2 -4 0 5
-1
n,d=map(int,input().split())
a=list(map(int,input().split()))
if a[0]==0:
    a=a[1:]
    n-=1
add=0
maxi=-99999999999999999999999
base,height=[],[]
for i in range(n):
    if a[i]!=0:
        add+=a[i]
        maxi=max(maxi,add)
    else:
        base.append(add)
        height.append(maxi)
        add,maxi=add,-99999999999999999999
if a[-1]!=0:
    height.append(maxi)
else:
    height.append(-9999999999)
height=height[1:]
count=0
flag=0
range_l,range_r=-10**6,-10**5
ans_l,ans_r=0,0
l=len(base)
for i in range(l):
    range_l=max(0-base[i],0)
    range_r=min(d-base[i],d-height[i])
    if range_l>range_r or height[i]>d:
        flag=-1
        break
    if max(range_r,ans_r)-min(range_l,ans_l)+1 < range_r-range_l+1 + ans_r-ans_l+1:
        ans_l=max(ans_l,range_l)
        ans_r=min(ans_r,range_r)
    else:
        ans_l=range_l
        ans_r=range_r
        count+=1
if flag==-1:
    print(-1)
else:
    print(count)