#include <bits/stdc++.h>
using namespace std;
int n, m, a[1024], b[1024], c[1024], d[1024], dp[1024][1024], now[1024][1024];
int main() {
  int i, j, x, y;
  a[0] = 0;
  b[0] = 0;
  cin >> n >> m >> c[0] >> d[0];
  for (i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  for (i = 0; i <= m; i++) {
    dp[i][0] = 0;
    now[0][i] = 0;
  }
  for (i = 0; i <= n; i++) {
    dp[0][i] = (i / c[0]) * d[0];
    now[0][i] = (i / c[0]) * d[0];
  }
  for (i = 1; i <= m; i++)
    for (j = 1; j <= n; j++) {
      if (a[i] - (b[i] * (j / c[i])) >= 0)
        now[i][j] = (j / c[i]) * d[i];
      else
        now[i][j] = now[i][j - 1];
    }
  for (i = 1; i <= m; i++)
    for (j = 1; j <= n; j++) {
      x = 0;
      y = j;
      while (x <= j && y >= 0) {
        dp[i][j] = max(dp[i][j], dp[i - 1][x] + now[i][y]);
        x++;
        y--;
      }
    }
  cout << dp[m][n] << endl;
  return 0;
}
