#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int dp[N][11];
int n, m, c0, d0;
int a[11], b[11], c[11], d[11];
int solve(int rn, int ind) {
  if (rn < 0) return -1e9;
  if (ind == m) return 0;
  int &ret = dp[rn][ind];
  if (ret != -1) return ret;
  ret = solve(rn - c0, ind) + d0;
  for (int i = 0; i <= 100 && b[ind] * i <= a[ind]; i++) {
    ret = max(ret, solve(rn - i * c[ind], ind + 1) + i * d[ind]);
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> c0 >> d0;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  memset(dp, -1, sizeof dp);
  cout << solve(n, 0) << endl;
  return 0;
}
