program diet;
var
s:array[1..500] of longint;
f:array[0..45000] of longint;
i,j,k,m,n,h:longint;
begin
assign(input,'diet.in');reset(input);
assign(output,'diet.out');rewrite(output);
readln(h,n);
for i:=1 to n do
readln(s[i]);
for i:=1 to n do
for j:=h downto 1 do
if j-s[i]>=0 then
if f[j-s[i]]+s[i]>f[j] then
f[j]:=f[j-s[i]]+s[i];
writeln(f[h]);
close(output);
end.