#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int n,m;
struct farmer{
int money;
int L;
}a[10000];
bool cmp(farmer a,farmer b){
return a.money < b.money;
}
int main(){
cin >> n >> m;
int i,j;
for(i = 1; i <= m; ++i){
cin >> a[i].money >> a[i].L;
}
sort(a+1,a+m+1,cmp);
long long sum = 0;
for(i = 1;; ++i){
if(n == 0)break;
if(a[i].L < n){
sum+=a[i].money*a[i].L;
n -= a[i].L;
}
if(a[i].L >= n){
sum+=a[i].money*n;
n = 0;
}
}
cout << sum ;
return 0;
}