#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long sum,sumj,n;
struct re
{
long long s,j;
};
struct re a[500009];
int myway(struct re a,struct re b)
{
if(a.j==b.j)
return a.s>=b.s;
else
return a.j<b.j;
}
int main()
{
cin>>sum>>n;
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i].j,&a[i].s);
sort(a+1,a+n+1,myway);
for(int i=1;i<=n;i++)
if(sum==0) break;
else
if(sum>=a[i].s)
{
sum-=a[i].s;
sumj+=a[i].s*a[i].j;
}
else
if(sum<a[i].s)
{
sumj+=sum*a[i].j;
sum=0;
}
cout<<sumj;
return 0;
}
求大神犇指点啊