#include <bits/stdc++.h>
using namespace std;
int RestNum[25];
int ThingsNum[25];
int Cost[25];
int Val[25];
int Dp[1001] = {0};
int V;
int m;
int max(int, int);
int main(void) {
  int C0, D0;
  cin >> V >> m;
  cin >> C0 >> D0;
  for (int i = 0; i <= V; i++) {
    Dp[i] = i / C0 * D0;
  }
  for (int i = 1; i <= m; i++) {
    int Restn;
    cin >> RestNum[i] >> Restn >> Cost[i] >> Val[i];
    ThingsNum[i] = RestNum[i] / Restn;
    for (int j = 1; j <= ThingsNum[i]; j++) {
      for (int k = V; k >= Cost[i]; k--) {
        Dp[k] = max(Dp[k], Dp[k - Cost[i]] + Val[i]);
      }
    }
  }
  cout << Dp[V] << endl;
  return 0;
}
int max(int a, int b) { return a > b ? a : b; }
