#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,sum,ans;
struct node{
int p,a;
}t[2000001];
bool cmp(node &x,node &y){
return x.p<y.p;
}
signed main(){
cin>>m>>n;
for (int i=1;i<=n;i++) cin>>t[i].p>>t[i].a;
sort(t+1,t+n+1,cmp);
for (int i=1;i<=n;i++){
if (ans+t[i].a<m){
sum+=t[i].a*t[i].p;
ans+=t[i].a;
}
else{
cout<<sum+(m-ans)*t[i].p;
return 0;
}
}
}