1 var i,j,k,t,w,now:longint;
2 tree:array[1..2,0..1001] of longint;
3 f:array[1..2,0..50,0..1001] of longint;
4 function max(a,b:longint):longint;
5 begin
6 if a>b then exit(a)
7 else exit(b);
8 end;
9 begin
10 readln(t,w);
11 for i:=1 to t do
12 begin
13 readln(now);
14 tree[now,i]:=1;
15 end;
16 for i:=1 to t do
17 for j:=0 to w+i-max(i,w) do
18 for k:=1 to 2 do
19 begin
20 if (j=0) and (k<>2) then begin
21 f[k,j,i]:=f[k,j,i-1]+tree[k,i];
22 continue;
23 end
24 else if j=0 then continue;
25 f[k,j,i]:=max(f[k,j,i],tree[k,i]+max(f[3-k,j-1,i-1],f[k,j,i-1]));
26 //writeln(i,' ',j,' ',f[k,j,i]);
27 end;
28 writeln(max(f[1,w,t],f[2,w,t]));
29 end.