program happy;
type node=record
v,p:integer;
end;
var
i,m,n:integer;
max:longint;
t:array [1..25] of node;
function judge(k:integer):boolean;
var i:integer;
begin
judge:=true;
for i:=1 to m do if k>=t[i].v then judge:=false;
end;
procedure go(no,k:integer;sum:longint);
var i:integer;
begin
if no<=m+1 then
if judge(k) then begin
if sum>max then max:=sum;
end
else for i:=1 downto 0 do
if (i=1) and (k>=t[no].v) then go(no+1,k-t[no].v,sum+t[no].v*t[no].p)
else if i=0 then go(no+1,k,sum)
end;
begin
assign (input,'happy.in');
reset (input);max:=0;
readln (n,m);
for i:=1 to m do readln (t[i].v,t[i].p);
close (input);
assign (output,'happy.out');
rewrite (output);
go(1,n,0);
writeln (max);
close (output);
end.