#include <bits/stdc++.h>
using namespace std;
const int infint = INT_MAX;
const long long infll = LLONG_MAX;
const int MAX = 1200;
long long dp[MAX][11][MAX];
long long n, m, c0, d0;
long long a[MAX], b[MAX], c[MAX], d[MAX];
long long go(int dog, int i, int taken) {
  if (dog < 0) return -1e9;
  if (taken * b[i] > a[i]) return -1e9;
  if (i >= m) return 0;
  if (dog == 0) return 0;
  if (dp[dog][i][taken] != -1) return dp[dog][i][taken];
  long long res = 0;
  res = max(go(dog - c[i], i, taken + 1) + d[i],
            max(go(dog, i + 1, 0), go(dog - c0, i, taken) + d0));
  return dp[dog][i][taken] = res;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> m >> c0 >> d0;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  cout << go(n, 0, 0);
  return 0;
}
