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