#include <bits/stdc++.h>
using namespace std;
const int iINF = numeric_limits<int>::max();
const long long lINF = numeric_limits<long long>::max();
int fastin() {
  register int x = 0, ch = getchar(), f = 0;
  while (!isdigit(ch)) (ch == '-') && (f = 1), ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
template <typename T>
bool checkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
bool checkmin(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
const int MAXN = 1010;
int n, m, c0, d0, dp[MAXN];
void work() {
  n = fastin(), m = fastin(), c0 = fastin(), d0 = fastin();
  for (register int i = 1; i <= n; ++i) dp[i] = i / c0 * d0;
  for (register int i = 1; i <= m; ++i) {
    int a = fastin(), b = fastin(), c = fastin(), d = fastin();
    for (register int j = 1; j <= a / b; ++j)
      for (register int k = n; k >= c; k--) checkmax(dp[k], dp[k - c] + d);
  }
  printf("%d\n", dp[n]);
}
signed main() {
  int _ = 1;
  while (_--) work();
  return 0;
}
