#include <bits/stdc++.h>
using namespace std;
const int maxn = 1050;
const int maxm = 15;
int n, m, a[maxm], b[maxm], c[maxm], d[maxm];
int ans, f[maxm][maxn];
void Init() {
  scanf("%d%d%d%d", &n, &m, &c[0], &d[0]);
  a[0] = n;
  for (int i = 1; i <= m; i++) scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
}
void Dp() {
  f[0][n] = 0;
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= n; j++)
      for (int k = 0; (c[i] * k <= j) && (b[i] * k <= a[i]); k++) {
        f[i + 1][j - c[i] * k] =
            max(f[i + 1][j - c[i] * k], f[i][j] + d[i] * k);
        ans = max(ans, f[i + 1][j - c[i] * k]);
      }
}
int main() {
  Init();
  Dp();
  printf("%d\n", ans);
  return 0;
}
