#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt[1005], c[1005], d[1005];
int dp[15][1005];
int solve(int dx, int dough) {
  if (dx == m + 1) return 0;
  int &sol = dp[dx][dough];
  if (sol != -1) return sol;
  sol = solve(dx + 1, dough);
  int take = 0;
  int add = 0;
  for (int i = 0; i < cnt[dx]; ++i) {
    take += c[dx];
    add += d[dx];
    if (take > dough) break;
    sol = max(sol, solve(dx + 1, dough - take) + add);
  }
  return sol;
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d%d", &c[0], &d[0]);
  cnt[0] = 100000;
  for (int i = 1; i <= m; ++i) {
    int f, s;
    scanf("%d%d%d%d", &f, &s, &c[i], &d[i]);
    cnt[i] = f / s;
  }
  memset(dp, -1, sizeof(dp));
  int sol = solve(0, n);
  printf("%d\n", sol);
  return 0;
}
