#include <bits/stdc++.h>
using namespace std;
int f[10010], n, m, c0, d0, a[10200], b[10200], c[10200], d[10200];
int main() {
  cin >> n >> m >> c0 >> d0;
  for (int i = c0; i <= n; i++) f[i] = i / c0 * d0;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    for (int j = 1; j <= a[i] / b[i]; j++)
      for (int k = n; k >= c[i]; k--) f[k] = max(f[k - c[i]] + d[i], f[k]);
  }
  cout << f[n];
}
