#include <bits/stdc++.h>
using namespace std;
int a[11], b[11], c[11], d[11];
int f[1111][11];
int main() {
  int n, m;
  cin >> n >> m >> c[0] >> d[0];
  a[0] = n;
  b[0] = 1;
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  memset(f, 0, sizeof(f));
  for (int i = 0; i <= n; i++)
    for (int k = 0; k <= a[0] / b[0] && k * c[0] <= i; k++)
      f[i][0] = max(f[i][0], f[i - k * c[0]][0] + d[0] * k);
  for (int i = 0; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      for (int k = 0; k <= a[j] / b[j] && k * c[j] <= i; k++) {
        f[i][j] = max(f[i][j], f[i - k * c[j]][j - 1] + d[j] * k);
      }
    }
  cout << f[a[0]][m];
  return 0;
}
