program diet;
var
h,n,t,i,j,max:longint;
sz:array[0..45000]of longint;
begin
assign(input,'diet.in');
assign(output,'diet.out');
reset(input);
rewrite(output);
readln(h,n);
fillchar(sz,sizeof(sz),0);
for i:=1 to n do
begin
readln(t);
for j:=h downto 1 do
if sz[j]<>0 then
if j+t<=h then
if sz[j+t]<sz[j]+t then sz[j+t]:=sz[j]+t;
if sz[t]<t then sz[t]:=t;
end;
max:=0;
for i:=h downto 1 do
if sz[i]<>0 then begin
max:=sz[i];
break;
end;
writeln(max);
close(input);
close(output);
end.