#include <bits/stdc++.h>
using namespace std;
int a[105], b[105], c[105], d[105], dp[1005][105];
int n, m, c0, d0;
int solve(int dough, int idx) {
  int ans = 0;
  if (dp[dough][idx] != -1) return dp[dough][idx];
  if (idx == m + 1) return 0;
  for (int i = 1; i * c0 <= dough; i++)
    ans = max(ans, i * d0 + solve(dough - i * c0, idx));
  for (int i = 0; i * c[idx] <= dough && i * b[idx] <= a[idx]; i++)
    ans = max(ans, i * d[idx] + solve(dough - i * c[idx], idx + 1));
  return dp[dough][idx] = ans;
}
int main() {
  (scanf("%d%d%d%d", &n, &m, &c0, &d0));
  for (int i = 1; i <= m; i++) (scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]));
  memset(dp, -1, sizeof(dp));
  cout << solve(n, 1);
}
