#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 30010;
int f[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin >> m >> n;
for(int i = 1; i <= n; i ++ )
{
int v,w;
cin >> v >> w;
for(int j = m; j >= v; j -- )
f[j] = max(f[j],f[j - v] + v*w);
}
cout << f[m] << "\n";
return 0;
}