#include<bits/stdc++.h>
#define int long long
#define QWQ cin.tie(0)->sync_with_stdio(false);
using namespace std;
struct Milk{
int price, cnt;
}milk[123456789];
signed main(){
QWQ
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++){
cin >> milk[i].price >> milk[i].cnt;
}
sort(milk + 1, milk + m + 1, [](Milk a, Milk b)->bool{return a.price < b.price;});
int resCnt = 0, resPrice = 0, k = 1;
bool flag = true;
while(flag){
if(resCnt + milk[k].cnt <= n){
resCnt += milk[k].cnt;
resPrice += milk[k].price * milk[k].cnt;
}
else{
resPrice += (n - resCnt) * milk[k].price;
flag = false;
}
++k;
}
cout << resPrice;
return 0;
}