#include <bits/stdc++.h>
using namespace std;
int dp[1005];
int main(void) {
  int n, m, c0, d0;
  scanf("%d%d%d%d", &n, &m, &c0, &d0);
  for (int i = c0; i <= n; i += c0) dp[i] = dp[i - c0] + d0;
  while (m--) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    a /= b;
    for (int i = n; i >= 0; --i)
      for (int j = 1; j <= a && i >= c * j; j++)
        dp[i] = max(dp[i], dp[i - c * j] + d * j);
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) ans = max(ans, dp[i]);
  printf("%d\n", ans);
  return 0;
}
