#include <bits/stdc++.h>
using namespace std;
int dp[1024];
int main() {
  int n, m, c, d;
  scanf("%d %d %d %d", &n, &m, &c, &d);
  for (int i = 0; i <= n; i++) {
    dp[i] = (int)(i / c) * d;
  }
  while (m--) {
    int num, x, y, s;
    scanf("%d %d %d %d", &num, &x, &y, &s);
    num /= x;
    while (num--) {
      for (int i = n; i >= y; i--) dp[i] = max(dp[i], dp[i - y] + s);
    }
  }
  int mm = 0;
  for (int i = 0; i <= n; i++) mm = max(mm, dp[i]);
  printf("%d\n", mm);
  return 0;
}
