var n,m,i,j,sum1,sum2:longint;
f,a:array[0..5005]of 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 sum1:=1 else sum2:=1;
for j:=i-1 downto 0 do
begin
if not( (abs(sum1-sum2)>m)and not((sum1=0)or(sum2=0)) )then
f[i]:=min(f[i],f[j]+1);
if a[j]=1 then inc(sum1);
if a[j]=2 then inc(sum2);
end;
end;
writeln(f[n]);
close(input);close(output);
end.