var
f:array [1..35000] of longint;
b,c:longint;
v:array [1..21] of longint;
i,j:longint;
begin
read(c,b);
for i:=1 to b do read(v[i]);
for i:=1 to b do for j:=c downto v[i] do
if f[j]
end.
var
a:array[0..35000]of boolean;
f:array[1..21]of longint;
b,c,i,j:longint;
begin
fillchar(a,sizeof(a),false);
a[0]:=true;
read(c,b);
for i:=1 to b do
read(f[i]);
for i:=1 to b do
for j:=c downto f[i] do
a[j]:=a[j-f[i]] or a[j];
for i:=c downto 0 do
if a[i] then begin
writeln(i); halt;
end;
end.