var
a,b,c,d,e,i,j,m,n,x,y:longint;
k,f:array[0..25000]of longint;
begin
assign(input,'orz.in');
assign(output,'orz.out');
reset(input); rewrite(output);
read(n,m);
for a:=1 to n do
readln(k[a]);
for a:=1 to n do
f[a]:=9999999;
for a:=0 to n-1 do
begin
x:=0; y:=0;
for b:=a+1 to n do
begin
if k[b]=2 then inc(y);
if k[b]=1 then inc(x);
if (abs(x-y)<=m)or(x=0)or(y=0) then
begin
if f[b]>f[a]+1 then
f[b]:=f[a]+1;
end;
end;
end;
writeln(f[n]);
close(input);
close(output);
end.