var
m,n,b,c,ans:longint;
a,p:array[1..5000]of longint;
procedure kuaipai(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l;j:=r;x:=p[(i+j)div 2];
repeat
while p[i]<x do inc(i);
while x<p[j] do dec(j);
if i<=j then
begin
y:=a[i];a[i]:=a[j];a[j]:=y;
y:=p[i];p[i]:=p[j];p[j]:=y;
inc(i);dec(j);
end;
until i>j;
if i<r then kuaipai(i,r);
if j>l then kuaipai(l,j);
end;
begin
assign(input,'milk.in');
assign(output,'milk.out');
reset(input);
rewrite(output);
read(n,m);
for m:=1 to m do
read(p[m],a[m]);
kuaipai(1,m);
b:=1;
repeat
if a[b]<n then
begin
n:=n-a[b];
ans:=ans+a[b]*p[b];
end
else
begin
ans:=ans+n*p[b];
n:=0;
end;
inc(b);
until n=0;
writeln(ans);
close(input);close(output);
end.