type
integer=longint;
var
sum:int64;
m,n,i,j:integer;
x:array[0..50000] of boolean;
a:array[0..5000] of integer;
begin
assign(input,'hay4sale.in');
reset(input);
assign(output,'hay4sale.out');
rewrite(output);
read(m,n);
for i:=1 to n do
begin
read(a[i]);
sum:=sum+a[i];
end;
x[0]:=true;
if sum>50000 then sum:=50000;
for i:=1 to n do
begin
j:=sum+1;
repeat
j:=j-1;
if x[j-a[i]] then x[j]:=true;
until j=a[i];
end;
for i:=m to sum+1 do
if x[i]=true then break;
write(i);
close(input);
close(output);
end.