#include<bits/stdc++.h>
int main(){
int n,m,z;
unsigned int q;
int H[50][2]={{0},{0}};
scanf("%d %d",&n,&m);
for(int i=0;i<m;i++){
scanf("%d %d",&H[i][1],&z);
H[i][0]=H[i][1]*z;
}
for(int i=0;i<m-1;i++){
for(int j=0;j<m-i-1;j++){
int temp=0;
int temp1=0;
if(H[j][0]<H[j+1][0]){
temp=H[j][0];
H[j][0]=H[j+1][0];
H[j+1][0]=temp;
temp1=H[j][1];
H[j][1]=H[j+1][1];
H[j+1][1]=temp1;
}
}
}
int b=0;
int con=0;
int tou=0;
for(int i=0;i<m-1;i++){
if(H[i][0]==H[i+1][0]){
if(b==0){
tou=i;
b=1;
}
con++;
}
if((H[i][0]!=H[i+1][0]&&b==1)||con==m-1){
for(int i=con;i>0;i--){
for(int j=0;j<i;j++){
if(H[j+tou][1]>H[j+tou+1][1]){
int temp=H[j+tou][1];
H[j+tou][1]=H[j+tou+1][1];
H[j+tou+1][1]=temp;
int temp0=H[j+tou][0];
H[j+tou][0]=H[j+tou+1][0];
H[j+tou+1][0]=temp0;
}
}
}
b=0;
con=0;
tou=0;
}
}
int q1=0;
for(int i=0;i<m;i++){
if(q1+H[i][1]>n){continue;}
q += H[i][0];
q1 += H[i][1];
}
printf("%d",q);
return 0;
}