#include<bits/stdc++.h>
#define int long long
using namespace std;
auto IN = freopen("topic.in", "r", stdin);
auto OUT = freopen("topic.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 205, M = 25;
int n = mread(), m = mread(), a[M], b[M], f[M][N];
int mi(int x, int k){
int ans = 1;
for(int i = 1; i <= k; i ++){
ans *= x;
}
return ans;
}
signed main(){
for(int i = 1; i <= m; i ++){
cin >> a[i] >> b[i];
}
memset(f, 0x3f, sizeof(f));
f[0][0] = 0;
for(int i = 1; i <= m; i ++){
f[i][0] = 0;
for(int j = 1; j <= n; j ++){
for(int k = 0; k <= j; k ++){
f[i][j] = min(f[i][j], f[i - 1][j - k] + a[i] * mi(k, b[i]));
}
}
}
printf("%lld\n", f[m][n]);
return 0;
}