var a,f:array[-5..2505]of longint;
n,m,i,j,sum1,sum2:longint;
function min(a,b:longint):longint;
begin
if a<b then min:=a
else min:=b;
end;
begin
assign(input,'orz.in');reset(input);
assign(output,'orz.out');rewrite(output);
readln(n,m);
for i:=1 to n do readln(a[i]);
fillchar(f,sizeof(f),100);
f[0]:=0;
for i:=1 to n do
begin
sum1:=0; sum2:=0;
if a[i]=1 then inc(sum1) else inc(sum2);
for j:=i-1 downto 0 do
begin
if(abs(sum1-sum2)<=m)or(sum1=0)or(sum2=0)then
f[i]:=min(f[i],f[j]+1);
if a[j]=1 then inc(sum1) else inc(sum2);
end;
end;
writeln(f[n]);
close(input);close(output);
end.