#include <bits/stdc++.h>
using namespace std;
int N, T, M, K;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int C0, D0;
  int a[105], b[105], c[105], d[105];
  a[0] = 0;
  b[0] = 0;
  c[0] = 0;
  d[0] = 0;
  int dp[1010][110];
  memset(dp, 0, sizeof dp);
  cin >> N >> M >> C0 >> D0;
  for (int i = 1; i <= M; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      for (int k = 0; k <= int(a[j] / b[j]); k++) {
        if (i - (c[j] * k) >= 0) {
          dp[i][j] = max(dp[i][j], dp[i - (c[j] * k)][j - 1] + k * d[j]);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= N; i++) {
    ans = max(ans, dp[i][M] + (((N - i) / C0) * D0));
  }
  cout << ans << endl;
  return 0;
}
