program diet;
var
a:array[0..501]of longint;
f:array[0..501,0..45001]of longint;
h,i,j,n:longint;
procedure ma;
begin
for i:=1 to h do f[0,i]:=0;
for i:=1 to n do
for j:=1 to h do begin
f[i,j]:=f[i-1,j];
if (j>=h)and(f[i-1,j-h]+a[i]>f[i,j])then f[i,j]:=f[i-1,j-h]+a[i]
end;
end;
begin
assign(input,'diet.in');
assign(output,'diet.out');
reset(input); rewrite(output);
readln(h,n);
for i:=1 to n do readln(a[i]);
writeln(f[n,h]);
close(input); close(output);
end.