program happy;
var
a,b,n,m,i,j:longint;
f:array[0..25,0..30000]of longint;
jz,tj:array[1..25]of longint;
begin
assign (input,'happy.in');
reset (input);
assign (output,'happy.out');
rewrite (output);
readln (n,m);
for i:=1 to m do
begin
readln (a,b);
tj[i]:=a;
jz[i]:=a*b
end;
for i:=1 to m do
for j:=1 to n do
begin
f[i,j]:=f[i-1,j];
if j-tj[i]>=0 then
if f[i-1,j-tj[i]]+jz[i]>=f[i,j] then
f[i,j]:=f[i-1,j-tj[i]]+jz[i]
end;
writeln (f[m,n]);
close (input);
close (output)
end.