var
a:array[0..10000]of longint;
c,h,p,max:longint;
procedure move(m,i:longint);
var
j,k:longint;
begin
k:=m;j:=i;
if (k+a[i]<=c)and(j<=h) then
begin
move(k+a[i],j+1);
move(k,j+1);
end
else
if (j+1<=h) then move(k,i+1);
if k>max then max:=k;
end;
begin
assign(input,'hay4sale.in');
assign(output,'hay4sale.out');
reset(input);
rewrite(output);
read(c,h);
for p:=1 to h do
read(a[p]);
move(0,1);
writeln(max);
close(input);
close(output);
end.