var
i,j,k,z,m,min:longint;
a:array [1..5002] of longint;
begin
assign(input,'hay4sale.in');
reset(input);
assign(output,'hay4sale.out');
rewrite(output);
read(z,m);
for i:=1 to m do
readln(a[i]);
for i:=1 to m-1 do
for j:=i+1 to m do
if a[i]>a[j] then begin
k:=a[i];
a[i]:=a[j];
a[j]:=k;
end;
for i:=1 to m do
if a[i]=z then begin
write(z);
exit;
end;
min:=10000;
for i:=1 to m do
begin
k:=1;
repeat
j:=a[k]+a[i];
if j=z then
begin
write(z);
exit;
end;
if j<z then
min:=z-j;
k:=k+1;
until k=m;
end;
for i:=1 to m do
if min>=a[i] then min:=min-a[i];
write(z-min);
close(input);
close(output);
end.