program ex(f1,f2);
type
zn=array [0..10000] of longint;
ha=array [1..25] of integer;
var
a:zn; v,w:ha; f1,f2:text; i,j,m,n,k:integer;
answer:longint;
begin
assign(f1,'happy.in'); reset(f1);
assign(f2,'happy.out'); rewrite(f2);
readln(f1,n,m);
for i:=1 to m do
readln(f1,v[i],w[i]);
for i:=1 to n do a[i]:=0;
for i:=1 to m do
for j:=n downto v[i] do
if (j-v[i]>=0) and ((a[j-v[i]]+(v[i]*w[i]))>a[j]) then
a[j]:=a[j-v[i]]+v[i]*w[i];
answer:=0;
for i:=1 to n do
if a[i]>answer then answer:=a[i];
writeln(f2,answer);
close(f1);
close(f2);
end.