!!!#6WA!!!
#include<bits/stdc++.h>
using namespace std;
long long n,m,summ;
struct cow{
long long d,s;
}a[5005];
bool cmpp(cow x,cow y)
{
if(x.d != y.d)
return x.d<y.d;
else if(x.s != y.s)
return x.s>y.s;
return true;
}
int main()
{
cin>>n>>m;
for(int i=0; i<m; i++)
cin>>a[i].d>>a[i].s;
sort(a,a+m,cmpp);
int i=0;
while(n > 0)
{
if(a[i].s > 0)
{
a[i].s--;
summ+=a[i].d;
n--;
}
else
i++;
}
cout<<summ;
return 0;
}