var
v:array[1..5000]of longint;
v1:array[1..5000]of boolean;
a:array[0..100001]of boolean;
p:array[1..100002]of longint;
i,j,k,h,c,max:longint;
begin
assign(input,'hay4sale.in');
assign(output,'hay4sale.out');
reset(input);
rewrite(output);
read(c,h);
a[0]:=true;
for i:=1 to h do
begin
read(v[i]);
v1[i]:=true;
end;
max:=1;
p[1]:=0;
for i:=1 to h do
for j:=1 to max do
if (v[i]+p[j]<=c)and not(a[v[i]+p[j]]) then begin
max:=max+1;
a[v[i]+p[j]]:=true;
p[max]:=v[i]+p[j];
end;
for i:=c downto 1 do
if a[i] then begin writeln(i);break;end;
close(input);
close(output);
end.