program zht;
var
x,z:array[1..5000] of longint;
s,n,i,j,d,t,jk:longint;
begin
assign(input,'milk.in');
assign(output,'milk.out');
reset(input);
rewrite(output);
readln(s,n);
for i:=1 to n do
readln(z[i],x[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
if z[i]>=z[j] then
begin
d:=z[i];
z[i]:=z[j];
z[j]:=d;
d:=x[i];
x[i]:=x[j];
x[j]:=d;
end;
d:=0;
t:=0;
while d<s do
begin
inc(t);
if d+x[t]<=s then begin d:=d+x[t];jk:=z[t]*x[t]+jk;end
else begin jk:=jk+(z[t]*(s-d));writeln(jk);exit;end;
end;
writeln(jk);
close(input);
close(output);
end.