program diet;
type
fxz1=array[0..45000] of boolean;
fxz2=array[1..500] of longint;
var
f1,f2:text;
i,j,n,m:longint;
flag:fxz1;
a:fxz2;
begin assign(f1,'diet.in');
assign(f2,'diet.out');
reset(f1);rewrite(f2);
readln(f1,n,m);
for i:=1 to m do
readln(f1,a[i]);
for i:=1 to n do flag[i]:=false;
flag[0]:=true;
for i:=1 to m do
for j:=n downto 0 do if (flag[j])and(j+a[i]<=n) then flag[j+a[i]]:=true;
while flag[n]=false do dec(n);
writeln(f2,n);
close(f1);close(f2);
end.