var
i,j,n,m:longint;
f,s,a:array[0..100000]of longint;
function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end;
function ok(x,y:longint):boolean;
var
now,l:longint;
begin
now:=s[y]-s[x-1];
l:=y-x+1;
if (now=l)or(now=0)or(abs(now-l+now)<=m) then exit(true);
exit(false);
end;
begin
assign(input,'orz.in'); reset(input);
assign(output,'orz.out'); rewrite(output);
readln(n,m);
for i:=1 to n do
begin
readln(a[i]);
dec(a[i]);
s[i]:=s[i-1]+a[i];
end;
for i:=1 to n do
begin
f[i]:=maxlongint;
for j:=1 to i do
if (ok(j,i))and(f[j-1]+1<f[i]) then
f[i]:=f[j-1]+1;
end;
writeln(f[n]);
close(input);
close(output);
end.