program happy;
type
fxz=array[0..1000000] of longint;
var
f1,f2:text;
i,j,n,t,max,k,time,money:longint;
a:fxz;
begin
assign(f1,'happy.in');
assign(f2,'happy.out');
reset(f1);rewrite(f2);
readln(f1,t,n);
for i:=0 to t do
a[i]:=0;
for i:=1 to n do
begin
readln(f1,time,money);
money:=money*time;
for j:=t downto 0 do
if ((a[j]<>0)and(j+time<=t))or(j=0) then
begin k:=a[j]+money;
if k>=a[j+time] then a[j+time]:=k;end;
end;
max:=0;
for i:=1 to t do
if a[i]>max then max:=a[i];
writeln(f2,max);
close(f1);close(f2);
end.