#include <bits/stdc++.h>
using namespace std;
struct ST{
int p,a;
};
ST A[100005];
int n,m,ans=0;
bool cmp(ST x,ST y){
if(x.a!=y.a)return x.p<y.p;
else return x.p>y.p;
}
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>A[i].p>>A[i].a;
}
sort(A+1,A+m+1,cmp);
int t=n,j=1;
while(t>0){
if(t-A[j].a>=0){
ans+=A[j].aA[j].p;
}
else{
ans+=A[j].pt;
}
t=t-A[j].a;
j++;
}
cout<<ans;
}