#include <bits/stdc++.h>
using namespace std;
const int sz = 5005;
const int mod = 998244353;
long long int n, a[sz], b[sz], dp[15][1005][1005], c[sz], d[sz], m, c0, d0;
long long int dipi(int i, int cnt, int rem) {
  if (rem > n) return -100000;
  if (i > m) return 0;
  if (~dp[i][cnt][rem]) return dp[i][cnt][rem];
  if (a[i] - cnt * b[i] < 0) {
    return dp[i][cnt][rem] = dipi(i + 1, 1, rem);
  }
  return dp[i][cnt][rem] =
             max({d[i] + dipi(i, cnt + 1, rem + c[i]), dipi(i + 1, 1, rem),
                  d[i] + dipi(i + 1, 1, rem + c[i])});
}
void solve() {
  cin >> n >> m >> c0 >> d0;
  memset(dp, -1, sizeof dp);
  c[0] = c0, d[0] = d0;
  a[0] = 0, b[0] = 0;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  cout << dipi(0, 1, 0) << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
