var
a,b,c,d,e,r,t,i,j,o,m,n,h:longint;
k:array[0..6000]of longint;
l:array[0..60000]of longint;
begin
assign(input,'hay4sale.in');
assign(output,'hay4sale.out');
reset(input);
rewrite(output);
read(c,h);
readln;
for a:=1 to h do
readln(k[a]);
l[0]:=1;
for i:=1 to h do
for j:=c downto 0 do
if (l[j]=1)and(j+k[i]<=c) then
l[j+k[i]]:=1;
for i:=c downto 0 do
if l[i]=1 then
begin
write(i);
break;
end;
close(input);
close(output);
end.