#include <cstdio>
#include <algorithm>
using namespace std;
int n,m,cnt=0,k=1,z=0;
struct node
{
int a,b;
} p[10005];
bool cmp(node x,node y)
{
if(x.a!=y.a) return x.a<y.a;
else return x.b>y.b;
}
int main()
{
scanf("%d %d",&n,&m);
for(int i=1;i<=m;i++)
scanf("%d %d",&p[i].a,&p[i].b);
sort(p+1,p+m+1,cmp);
while(cnt+p[k].b<=n)
{
cnt+=p[k].b;
z+=p[k].b*p[k].a;
k++;
}
z+=p[k].a*(n-cnt);
printf("%d",z);
return 0;
}