#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
  long long int n, m, c0, d0;
  cin >> n >> m >> c0 >> d0;
  vector<long long int> a(m + 1), b(m + 1), c(m + 1), d(m + 1);
  for (long long int i = 1; i < m + 1; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  long long int dp[n + 1][m + 1];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 0;
  for (long long int i = 1; i < n + 1; i++) {
    if (i < c0)
      dp[i][0] = 0;
    else
      dp[i][0] = (i / c0) * d0;
  }
  for (long long int i = 1; i < m + 1; i++) {
    dp[0][i] = 0;
  }
  for (long long int i = 1; i < n + 1; i++) {
    for (long long int j = 1; j < m + 1; j++) {
      long long int k = i;
      long long int h = a[j];
      dp[i][j] = dp[i][j - 1];
      long long int g = 1;
      while (k >= c[j] && h >= b[j]) {
        dp[i][j] = max(dp[i][j], dp[k - c[j]][j - 1] + (g * d[j]));
        g++;
        k -= c[j];
        h -= b[j];
      }
    }
  }
  long long int maxx = -1;
  for (long long int i = 0; i < m + 1; i++) maxx = max(maxx, dp[n][i]);
  cout << maxx;
}
