#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int M = 105;
int n, m, c0, d0, a[M], b[M], c[M], d[M];
int ct, f[N], v[N << 1], cost[N << 1];
int main() {
  int i, j, tmp, tmp2;
  scanf("%d%d%d%d", &n, &m, &c0, &d0);
  for (i = 0; i < m; i++) scanf("%d%d%d%d", a + i, b + i, c + i, d + i);
  ct = 0;
  tmp = n;
  while (tmp >= c0) {
    v[ct] = d0;
    cost[ct++] = c0;
    tmp -= c0;
  }
  for (i = 0; i < m; i++) {
    tmp = n;
    tmp2 = a[i];
    while (tmp >= c[i] && tmp2 >= b[i]) {
      v[ct] = d[i];
      cost[ct++] = c[i];
      tmp -= c[i];
      tmp2 -= b[i];
    }
  }
  memset(f, 0, sizeof(f));
  for (i = 0; i < ct; i++)
    for (j = n; j >= cost[i]; j--) f[j] = max(f[j], f[j - cost[i]] + v[i]);
  printf("%d\n", f[n]);
  return 0;
}
