program happy;
type
shuzu=array[0..10000] of longint;
shuzu1=array[0..30000]of longint;
var
v,w:shuzu;
b:shuzu1;
i,j,m,n:longint;
f1,f2:text;
function max(x,y:longint):longint;
begin
if x>y then max:=x
else max:=y;
end;
begin
assign(f1,'happy.in');reset(f1);
assign(f2,'happy.out');rewrite(f2);
readln(f1,n,m);
for i:=1 to m do
begin
readln(f1,v[i],w[i]);
w[i]:=v[i]*w[i];
end;
for i:=1 to m do
for j:=n downto v[i] do
begin
b[j]:=max(b[j],b[j-v[i]]+w[i]);
end;
writeln(f2,b[n]);
close(f1);close(f2);
end.