var
m,n,i:longint;
a:Array[0..1000000]of longint;
v:array[0..1000000]of boolean;
max:int64;
procedure go(k,t:longint; s:int64);
var
i:longint;
begin
if (k=0)and(t=-1) then
begin
if s>max then max:=s;
exit;
end;
if t=1 then
begin
for i:=1 to m do
if k+i<=n then
begin
v[k+i]:=true;
go(k+i,t,s+a[k+i]);
v[k+i]:=false;
end;
go(k,-1,s);
end
else begin
if (k=n)or(t=-1) then
begin
for i:=1 to m do
if (not v[k-i])and(k>=i)and(v[k-i+1]) then
begin
v[k-i]:=true;
go(k-i,-1,s+a[k-i]);
v[k-i]:=false;
end;
end;
end;
end;
begin
assign(input,'hop.in'); reset(input);
assign(output,'hop.out'); rewrite(output);
readln(n,m);
for i:=1 to n do read(a[i]);
max:=-maxlongint;
go(0,1,0);
writeln(max);
close(input);
close(output);
end.