#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int a = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) a = (a << 3) + (a << 1) + ch - '0';
  return a * f;
}
void write(int x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar((x % 10) ^ 48);
}
inline void writen(int x) {
  write(x);
  puts("");
}
const int mod = 1e9 + 7;
const int N = 1e4 + 5;
const int inf = 0x3f3f3f3f;
const int INF = 2147483647;
const double PI = acos(-1);
int f[N], n, m, c0, d0, ans;
int a[N], b[N], c[N], d[N];
signed main() {
  n = read();
  m = read();
  c0 = read();
  d0 = read();
  for (int i = c0; i <= n; i++) f[i] = i / c0 * d0;
  for (int i = 1; i <= m; i++) {
    a[i] = read();
    b[i] = read();
    c[i] = read();
    d[i] = read();
    for (int j = 1; j <= a[i] / b[i]; j++)
      for (int k = n; k >= c[i]; k--) f[k] = max(f[k - c[i]] + d[i], f[k]);
  }
  writen(f[n]);
  return 0;
}
