#include <bits/stdc++.h>
using namespace std;
int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int N, M, ci, di;
vector<int> stulf_left, stuf, c, d;
int dp[1001][11];
int rec(int dou, int idx) {
  if (dou <= 0) return 0;
  if (idx >= M) {
    if (dou <= 0)
      return 0;
    else
      return (dou / ci) * di;
  }
  if (dp[dou][idx] != -1) return dp[dou][idx];
  int prof = 0;
  for (int k = 0; k * stuf[idx] <= stulf_left[idx]; k++) {
    if (dou - c[idx] * k < 0) break;
    prof = max(prof, (d[idx] * k) + rec(dou - c[idx] * k, idx + 1));
  }
  return dp[dou][idx] = prof;
}
int main() {
  memset(dp, -1, sizeof dp);
  ;
  cin >> N >> M >> ci >> di;
  for (long long i = 0; i < M; i++) {
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    stulf_left.push_back(a);
    stuf.push_back(b);
    c.push_back(x);
    d.push_back(y);
  }
  cout << rec(N, 0);
}
