program jifang;
var
n,m,i,j,d1,d2:longint;
one,two,f,a:array[0..2500]of longint;
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]);
if a[i]=1 then
begin
one[i]:=one[i-1]+1;
two[i]:=two[i-1]
end
else
begin
one[i]:=one[i-1];
two[i]:=two[i-1]+1
end
end;
for i:=1 to n do
f[i]:=maxlongint;
f[0]:=0;
for i:=1 to n do
for j:=1 to i do
begin
d1:=one[i]-one[j-1];
d2:=two[i]-two[j-1];
if (d1=0)or(d2=0)or(abs(d1-d2)<=m) then
if f[j-1]+1<f[i] then
f[i]:=f[j-1]+1
end;
writeln(f[n]);
close (input);
close (output)
end.