#include <bits/stdc++.h>
using namespace std;
long long t, n, u, v, m, q, r, ql, qr, k, l, s, x, y;
const int N = 1e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57LL;
const bool JUDGE = false;
long long dp[1010][20];
long long a[N], b[N], c[N], d[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  if (JUDGE) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
  cin >> n >> m >> c[0] >> d[0];
  for (int i = 1; i <= m; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i) {
      dp[i][j] = dp[i][j - 1];
      for (long long k = 1; i - k * c[j] >= 0; k++) {
        if (k * b[j] > a[j]) break;
        dp[i][j] = max(dp[i][j], dp[i - k * c[j]][j - 1] + k * d[j]);
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i <= m; ++i) {
    for (int j = 0; j <= n; ++j) {
      ans = max(ans, dp[j][i] + ((int)((n - j) / c[0]) * d[0]));
    }
  }
  cout << ans << '\n';
  return 0;
}
