#include <bits/stdc++.h>
using namespace std;
int bag[1005];
int main() {
  int n, m, c0, d0, a, b, c, d, ans;
  scanf("%d%d%d%d", &n, &m, &c0, &d0);
  memset(bag, -1, sizeof(bag));
  bag[0] = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    for (int j = 0; j < a / b; j++) {
      for (int k = n; k >= c; k--) {
        if (bag[k - c] != -1) {
          bag[k] = max(bag[k], bag[k - c] + d);
        }
      }
    }
  }
  ans = 0;
  for (int i = 0; i <= n; i++) {
    if (bag[i] != -1) {
      ans = max(ans, bag[i] + (n - i) / c0 * d0);
    }
  }
  printf("%d\n", ans);
  return 0;
}
