program orz1;
var
n,m,i,j:longint;
a,b,sum,f:array[0..2500] of longint;
function ok(j,i:longint):boolean;
begin
if (abs(sum[i]-sum[j-1])<=m)
or(abs(sum[i]-sum[j-1])=i-j+1) then
exit(true);
exit(false);
end;
begin
assign(input,'orz.in');
assign(output,'orz.out');
reset(input);
rewrite(output);
readln(n,m);
for i:=1 to n do
begin
read(a[i]);
if a[i]=2
then b[i]:=-1
else b[i]:=1;
sum[i]:=sum[i-1]+b[i];
f[i]:=1000000000;
end;
f[0]:=0;
f[1]:=1;
for i:=1 to n do
for j:=i-1 downto 0 do
begin
if ok(j+1,i) then
if f[i]>(f[j]+1)
then f[i]:=f[j]+1;
end;
writeln(f[n]);
close(input);
close(output);
end.