#include <bits/stdc++.h>
using namespace std;
const int N =2e7;
struct farmer{
int p,q;
}fm[N];
int n,m,hasmilk = 0,cost = 0;
inline bool cmp(farmer a,farmer b){
return a.p < b.p;
}
int main(){
cin >> n >> m;
for (int i = 1;i <= m;i++)cin >> fm[i].p >> fm[i].q;
sort(fm+1,fm+m+1,cmp);
for (int i = 1;i <= m;i++){
for (int j = 1;j <= fm[i].q;j++){
if (hasmilk >= n){
cout << cost ;
return 0;
}
else hasmilk++;cost += fm[i].p;
}
}
printf("%d",0);
return 0;
}