program ex;
type
ss=array[1..500]of longint;
sz=array[0..45000]of longint;
var
f:ss;
ans:sz;
h,n:longint;
procedure init;
var
i:longint;
begin
assign(input,'diet.in');
assign(output,'diet.out');
reset(input);
rewrite(output);
readln(h,n);
for i:=1 to n do readln(f[i]);
close(input);
end;
procedure main;
var
i,j:longint;
begin
for i:=1 to n do
for j:=h downto 1 do
begin
if f[i]<=j then
if ans[j-f[i]]+f[i]>ans[j] then ans[j]:=ans[j-f[i]]+f[i];
end;
writeln(ans[h]);
close(output);
end;
begin
init;
main;
end.