include[HTML_REMOVED]
#include[HTML_REMOVED]
using namespace std;
const int N = 1010;
int f[N], v[N], w[N];
int main() {
int n, m;
cin >> m >> n;
for (int i = 0; i < n; i) cin >> v[i] >> w[i];
for (int i = 0; i < n; i) {
for (int j = m; j >= v[i]; –j)
f[j] = max(f[j], f[j - v[i]] + w[i]);
}
cout << f[m];
return 0;
}