#include <bits/stdc++.h>
using namespace std;
long long krit, w[2001], p[2001], dp[2001][1001], am = 0, a, b, c, d, m;
int main() {
  scanf("%ld %ld %ld %ld", &krit, &m, &c, &d);
  for (int i = 1; i <= krit / c; i++) {
    am++;
    p[am] = d;
    w[am] = c;
  }
  for (int i = 0; i < m; i++) {
    scanf("%ld %ld %ld %ld", &a, &b, &c, &d);
    for (int j = 1; j <= a / b; j++) {
      am++;
      p[am] = d;
      w[am] = c;
    }
  }
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= am; i++)
    for (int j = 1; j <= krit; j++)
      if (j >= w[i])
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + p[i]);
      else
        dp[i][j] = dp[i - 1][j];
  printf("%ld", dp[am][krit]);
  return 0;
}
