type m=record
q,s:longint;
end;
var
a:array[1..5050] of m;
t:m;
n,l,i,j,k,ans:longint;
begin
assign(input,'milk.in');
assign(output,'milk.out');
reset(input);
rewrite(output);
readln(l,n);
for i:=1 to n do
readln(a[i].q,a[i].s);
for i:=1 to n-1 do
begin
for j:=i+1 to n do
if a[i].q>a[j].q then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
end;
for i:=1 to n do
if l<a[i].s then
break else
begin
ans:=ans+a[i].s*a[i].q;
l:=l-a[i].s;
end;
ans:=ans+l*a[i].q;
writeln(ans);
close(input);
close(output);
end.