#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
int dp[1010];
int w[maxn], c[maxn], num[maxn];
int main() {
  int n, m, c0, d0;
  while (~scanf("%d%d%d%d", &n, &m, &c0, &d0)) {
    int ai, bi, ci, di;
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < m; i++) {
      scanf("%d%d%d%d", &ai, &bi, &ci, &di);
      num[i] = ai / bi;
      c[i] = di;
      w[i] = ci;
    }
    num[m] = n / c0;
    c[m] = d0;
    w[m] = c0;
    for (int i = 0; i <= m; i++) {
      for (int j = n; j >= 0; j--)
        for (int k = 0; k <= num[i]; k++) {
          if (j >= k * w[i]) dp[j] = max(dp[j], dp[j - k * w[i]] + c[i] * k);
        }
    }
    printf("%d\n", dp[n]);
  }
}
