#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long max(long long x, long long y) {
  if (x > y)
    return x;
  else
    return y;
}
long long min(long long x, long long y) {
  if (x > y)
    return y;
  else
    return x;
}
struct cl {
  long long a, b, c, d;
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long i, j, k, n, m, co, dd, p, q, ans = 0;
  cin >> n >> m >> co >> dd;
  vector<cl> v(m + 1);
  v[0].a = 0, v[0].b = 0, v[0].c = co, v[0].d = dd;
  map<long long, vector<long long>> dp;
  for (long long i = 0; i < m; i++) {
    cin >> j >> k >> p >> q;
    v[i + 1].a = j;
    v[i + 1].b = k;
    v[i + 1].c = p;
    v[i + 1].d = q;
  }
  vector<long long> ar(12);
  for (long long i = 0; i < n + 1; i++) {
    if (dp.count(i) == 0) dp[i] = ar;
    for (long long j = 0; j < m + 1; j++) {
      p = i + v[j].c;
      if (dp.count(p) == 0) dp[p] = ar;
      if (((p) <= n) && (dp[p][11] < (dp[i][11] + v[j].d))) {
        if ((dp[i][j] + v[j].b) <= v[j].a) {
          dp[p] = dp[i];
          dp[p][j] += v[j].b;
          dp[p][11] = dp[i][11] + v[j].d;
        }
      }
    }
  }
  for (long long i = 0; i < n + 1; i++) ans = max(ans, dp[i][11]);
  cout << ans;
  return 0;
}
