program a1;
var
i,h,c,max,m:longint;
a:array[0..10000]of longint;
//--------------------------------//
procedure f(i,m:longint);
begin
if (m>max)and(m<=c) then max:=m;
if max=c then
begin
writeln(c);
halt;
end;
if (m+a[i]<=c)and(i<=h) then f(i+1,m+a[i]);
if i<=h then
f(i+1,m);
end;
//-------------------------------//
begin
assign(input,'hay4sale.in');
reset(input);
assign(output,'hay4sale.out');
rewrite(output);
readln(c,h);
for i:=1 to h do
begin
readln(a[i]);
if a[i]=c then
begin
writeln(c);
halt;
end;
end;
f(1,0);
writeln(max);
close(input);
close(output);
end.