#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct thing{
ll v,p;
}t[100];
int m,n;
ll dp[200][20003];
int main(){
cin>>m>>n;
for(int i=1;i<=n;i++){
cin>>t[i].v>>t[i].p;
}
for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++){
if(j>=t[i].v){
dp[i][j]=max(dp[i-1][j],dp[i-1][j-t[i].v]+t[i].v*t[i].p);
}
else{
dp[i][j]=dp[i-1][j];
}
}
}
cout<<dp[n][m];
return 0;
}