#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstdio>
using namespace std;
int n,m,ans=0;
struct H{
int p,a;
}milk[5009];
int my_comp(const H&x,const H&y)
{
if(x.p<y.p) return 1;
return 0;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&milk[i].p,&milk[i].a);
}
sort(milk+1,milk+m+1,my_comp);
for(int i=1;i<=m;i++)
{
if(milk[i].a<=n)
{
ans+=milk[i].p*milk[i].a;
n-=milk[i].a;
}
else
ans+=n*milk[i].p,n=0;
if(n==0) break;
}
printf("%d",ans);
return 0;
}