#include <bits/stdc++.h>
using namespace std;
void chkmax(int &x, int y) { x = x > y ? x : y; }
int dp[10005];
int n, m, c0, d0;
int main() {
  scanf("%d%d%d%d", &n, &m, &c0, &d0);
  memset(dp, 0, sizeof(dp));
  for (int i = c0; i <= n; i++) dp[i] = i / c0 * d0;
  for (int i = 0; i < m; i++) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    for (int j = 1; j <= a / b; j++) {
      for (int k = n; k >= c; k--) {
        chkmax(dp[k], dp[k - c] + d);
      }
    }
  }
  printf("%d\n", dp[n]);
  return 0;
}
