program bly(input,output);
var
f:array[0..45000] of longint;
data:array[1..500] of longint;
h:longint;
i,j,n:longint;
f1,f2:text;
function max(x,y:longint):longint;
begin
if x>=y then max:=x
else max:=y;
end;
begin
assign(f1,'diet.in');
reset(f1);
readln(f1,h,n);
for i:=1 to n do read(f1,data[i]);
close(f1);
for i:=1 to n do begin
for j:=h downto 0 do begin
if j-data[i]>=0 then f[j]:=max(f[j],f[j-data[i]]+data[i]);
end;
end;
assign(f2,'diet.out');
rewrite(f2);
writeln(f2,f[h]);
close(f2);
end.