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