{
ID:angelxi1
PROG:milk
LANG:PASCAL
}
var
total,i,j,k,m,n:longint;
money:array[1..5000,1..2]of longint;
procedure init;
begin
readln(n,m);
for i:=1 to m do
for j:=1 to 2 do
read(money[i,j]);
end;
procedure sort(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l;j:=r;
x:=money[((l+r)shr 1),1];
repeat
while money[i,1]<x do
inc(i);
while money[j,1]>x do
dec(j);
if i<=j then
begin
y:=money[i,1];money[i,1]:=money[j,1];money[j,1]:=y;
y:=money[i,2];money[i,2]:=money[j,2];money[j,2]:=y;
inc(i);dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
assign(input,'milk.in');
assign(output,'milk.out');
reset(input);
rewrite(output);
init;
total:=0;
sort(1,m);
for i:=1 to m do
begin
k:=money[i,1]*money[i,2];
if (n-money[i,2])>0 then
begin
total:=total+k;
n:=n-money[i,2];
end
else
begin
total:=total+n*money[i,1];
writeln(total);
halt;
end;
end;
if total=0 then writeln(0);
close(input);
close(output);
end.
ID:angelxi1
PROG:milk
LANG:PASCAL
}
var
total,i,j,k,m,n:longint;
money:array[1..5000,1..2]of longint;
procedure init;
begin
readln(n,m);
for i:=1 to m do
for j:=1 to 2 do
read(money[i,j]);
end;
procedure sort(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l;j:=r;
x:=money[((l+r)shr 1),1];
repeat
while money[i,1]<x do
inc(i);
while money[j,1]>x do
dec(j);
if i<=j then
begin
y:=money[i,1];money[i,1]:=money[j,1];money[j,1]:=y;
y:=money[i,2];money[i,2]:=money[j,2];money[j,2]:=y;
inc(i);dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
assign(input,'milk.in');
assign(output,'milk.out');
reset(input);
rewrite(output);
init;
total:=0;
sort(1,m);
for i:=1 to m do
begin
k:=money[i,1]*money[i,2];
if (n-money[i,2])>0 then
begin
total:=total+k;
n:=n-money[i,2];
end
else
begin
total:=total+n*money[i,1];
writeln(total);
halt;
end;
end;
if total=0 then writeln(0);
close(input);
close(output);
end.