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