#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int i, n, m, j, v, cost, c0, d0;
  cin >> n >> m >> c0 >> d0;
  int a[m];
  int b;
  int c[m];
  int d[m];
  for (i = 0; i < m; i++) {
    cin >> a[i] >> b >> c[i] >> d[i];
    a[i] /= b;
  }
  int dp[n + 1][m + 1];
  for (i = 0; i < m + 1; i++) dp[0][i] = 0;
  for (i = 1; i <= n; i++) {
    v = -1;
    cost = dp[i - 1][m];
    if (i >= c0 && cost < d0 + dp[i - c0][m]) {
      cost = d0 + dp[i - c0][m];
      v = m;
    }
    for (j = 0; j < m; j++) {
      if (i >= c[j] && dp[i - c[j]][j] < a[j] &&
          cost < d[j] + dp[i - c[j]][m]) {
        cost = d[j] + dp[i - c[j]][m];
        v = j;
      }
    }
    if (v == -1)
      b = i - 1;
    else if (v == m)
      b = i - c0;
    else
      b = i - c[v];
    dp[i][m] = cost;
    for (j = 0; j < m; j++) dp[i][j] = dp[b][j];
    if (v >= 0 && v < m) dp[i][v]++;
  }
  cout << dp[n][m];
  return 0;
}
