#include <bits/stdc++.h>
using namespace std;
struct cel {
  int x, y, z, c;
} v[1010];
int cost[10100];
int N, M, c, d, rez;
void add(int q, int w) {
  for (int i = N; i >= 0; --i) {
    cost[i + q] = max(cost[i] + w, cost[i + q]);
  }
  return;
}
int main() {
  scanf("%d%d%d%d", &N, &M, &c, &d);
  for (int i = 1; i <= M; ++i)
    scanf("%d%d%d%d", &v[i].x, &v[i].y, &v[i].z, &v[i].c);
  cost[0] = 0;
  for (int i = 1; i <= N; ++i) cost[i] = -1234567;
  for (int i = 1; i <= N / c; ++i) add(c, d);
  for (int i = 1; i <= M; ++i) {
    for (int j = 1; j <= v[i].x / v[i].y; ++j) {
      add(v[i].z, v[i].c);
    }
  }
  for (int i = 1; i <= N; ++i) rez = max(rez, cost[i]);
  printf("%d", rez);
}
