#include<bits/stdc++.h>
using namespace std;
struct hk{
    int dj; 
    int sl;
}a[2000];
bool cmp(hk x,hk y){
    if(x.dj<y.dj) return true;
    else return false;
}
int main(){
    int m,n,s=0,c=0,t=0;
    cin>>m>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].dj>>a[i].sl;
    }
    sort(a+1,a+1+n,cmp);
    if(a[1].sl>=m) s=m*a[1].dj;
    else{
         s=s+a[1].dj*a[1].sl;
         c=c+a[1].sl;
         t=m-c;
       for(int i=2;i<=n;i++){
         if(a[i].sl>=t){
            s=s+a[i].dj*t;
            c=c+t;
         }else{
            s=s+a[i].dj*a[i].sl;
            c=c+a[i].sl;
            t=m-c;
            }
        if(c==m) break;     
       }
   }
   cout<<s;
}
/**************************************************************
	Problem: 1730
	User: wengsihan
	Language: C++
	Result: Accepted
	Time:21 ms
	Memory:2092 kb
****************************************************************/