var f:array[0..20000]of longint;
w,c:array[1..20000]of longint;
n,m,i,j:longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
begin
read(m,n);
for i:=1 to n do begin read(w[i]); c[i]:=w[i]; end;
for i:=1 to n do
for j:=m downto w[i] do f[j]:=max(f[j-w[i]]+c[i],f[j]);
writeln(m-f[m]);
end.
w,c:array[1..20000]of longint;
n,m,i,j:longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
begin
read(m,n);
for i:=1 to n do begin read(w[i]); c[i]:=w[i]; end;
for i:=1 to n do
for j:=m downto w[i] do f[j]:=max(f[j-w[i]]+c[i],f[j]);
writeln(m-f[m]);
end.