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