var
c,n,i,max:longint;
a:array[0..10000]of longint;
procedure dfs(w,s:longint);
var i:integer;
begin
if (s<=c)and(s>max) then max:=s;
if s=c then begin
write(c);
halt;
end;
if (s+a[w]<=c)and(w<=n) then dfs(w+1,s+a[w]);
if w<n then dfs(w+1,s);
if w>n then exit;
end;
BEGIN
assign(input,'hay4sale.in');
reset(input);
assign(output,'hay4sale.out');
rewrite(output);
read(c,n);
for i:=1 to n do read(a[i]);
for i:=1 to n do if a[i]=c then begin
write(c);
halt;
end;
dfs(1,0);
write(max);
close(input);
close(output);
END.