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