#include<bits/stdc++.h>
using namespace std;
long long f[21][300],n,m,j,k,A[210],B[210],sum[10000],ans=0;
int main(){
freopen("topic.in","r",stdin);
freopen("topic.out","w",stdout);
long long int p,i,j,k;
cin>>m>>n;
for(i=1;i<=n;i++)cin>>A[i]>>B[i];
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
for(k=0;k<=j;k++){
p=A[i]*pow(k,B[i]);
if(f[i][j]==0||i==1)f[i][j]=f[i-1][j-k]+p;
else
f[i][j]=min(f[i-1][j-k]+p,f[i][j]);
}
}
}
cout<<f[n][m];
}