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