var c,n,i,w,j,max,p:longint;
t: array[0..500] of longint;
function notfound(x:longint):boolean;
var i:longint;
begin
for i:=1 to t[0] do
if t[i]=x then
begin
notfound:=false;
exit;
end;
notfound:=true;
end;
begin
readln(c,n);
t[0]:=0;
max:=0;
for i:=1 to n do
begin
readln(w);
if (w<=c) then
begin
for j:=1 to t[0] do
begin
p:=t[j]+w;
if (notfound(p)) and (p<=c) then
begin
inc(t[0]);
t[t[0]]:=p;
if p>max then max:=p;
end;
end;
if notfound(w) then
begin
inc(t[0]);
t[t[0]]:=w;
if w>max then max:=w;
end;
end;
end;
writeln(max);
end.
ICAgIHZhciBjLG4saSx3LGosbWF4LHA6bG9uZ2ludDsKICAgICAgICB0OiBhcnJheVswLi41MDBdIG9mIGxvbmdpbnQ7CiAgICBmdW5jdGlvbiBub3Rmb3VuZCh4OmxvbmdpbnQpOmJvb2xlYW47CiAgICB2YXIgaTpsb25naW50OwogICAgYmVnaW4KICAgICAgZm9yIGk6PTEgdG8gdFswXSBkbwogICAgICBpZiB0W2ldPXggdGhlbiAKICAgICAgYmVnaW4KICAgICAgICBub3Rmb3VuZDo9ZmFsc2U7CiAgICAgICAgZXhpdDsKICAgICAgZW5kOwogICAgICBub3Rmb3VuZDo9dHJ1ZTsKICAgIGVuZDsKICAgIGJlZ2luCiAgICAgIHJlYWRsbihjLG4pOwogICAgICB0WzBdOj0wOwogICAgICBtYXg6PTA7CiAgICAgIGZvciBpOj0xIHRvIG4gZG8KICAgICAgYmVnaW4KICAgICAgICByZWFkbG4odyk7CiAgICAgICAgaWYgKHc8PWMpIHRoZW4KICAgICAgICBiZWdpbgogICAgICAgIGZvciBqOj0xIHRvIHRbMF0gZG8KICAgICAgICBiZWdpbgogICAgICAgICAgcDo9dFtqXSt3OwogICAgICAgICAgaWYgKG5vdGZvdW5kKHApKSBhbmQgKHA8PWMpIHRoZW4KICAgICAgICAgIGJlZ2luCiAgICAgICAgICAgIGluYyh0WzBdKTsKICAgICAgICAgICAgdFt0WzBdXTo9cDsKICAgICAgICAgICAgaWYgcD5tYXggdGhlbiBtYXg6PXA7CiAgICAgICAgICBlbmQ7CiAgICAgICAgZW5kOwogICAgICAgIGlmIG5vdGZvdW5kKHcpIHRoZW4KICAgICAgICBiZWdpbgogICAgICAgICAgaW5jKHRbMF0pOwogICAgICAgICAgdFt0WzBdXTo9dzsKICAgICAgICAgIGlmIHc+bWF4IHRoZW4gbWF4Oj13OwogICAgICAgIGVuZDsKICAgICAgICBlbmQ7CiAgICAgIGVuZDsKICAgICAgd3JpdGVsbihtYXgpOwogICAgZW5kLiA=