#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long mod) {
  long long c = 1;
  while (b > 0) {
    if (b % 2) c *= a, c %= mod;
    b /= 2;
    a *= a;
    a %= mod;
  }
  return c;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  vector<long long> c, d, b, a;
  cin >> n >> m;
  long long c0, d0;
  cin >> c0 >> d0;
  c.push_back(0);
  d.push_back(0);
  a.push_back(0);
  b.push_back(0);
  c.push_back(c0);
  d.push_back(d0);
  a.push_back(1);
  b.push_back(0);
  for (long long i = 0; i < m; i++) {
    long long aa, bb, cc, dd;
    cin >> aa >> bb >> cc >> dd;
    a.push_back(aa);
    b.push_back(bb);
    c.push_back(cc);
    d.push_back(dd);
  }
  long long dp[m + 3][n + 3];
  for (long long i = 0; i < n + 3; i++) {
    dp[0][i] = 0;
  }
  for (long long i = 0; i < m + 3; i++) {
    dp[i][0] = 0;
  }
  for (long long i = 1; i <= m + 1; i++) {
    for (long long j = 1; j <= n; j++) {
      long long dou = j;
      long long stuff = a[i];
      long long pro = dp[i - 1][dou];
      long long no_of_stuff = 0;
      while ((dou > 0) && (stuff > 0)) {
        dou -= c[i];
        stuff -= b[i];
        if ((dou >= 0) && (stuff >= 0)) {
          no_of_stuff++;
          pro = max(pro, no_of_stuff * d[i] + dp[i - 1][dou]);
        }
      }
      dp[i][j] = max(pro, dp[i - 1][j]);
    }
  }
  cout << dp[m + 1][n];
}
