#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y;
  int a[1005], b[1005], c[1005], d[1005];
  cin >> n >> m >> x >> y;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  int dp[1005][11];
  int temp, i, j, k, t;
  for (int i = 0; i <= n; i++) {
    dp[i][0] = 0;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      temp = -1;
      t = a[j] / b[j];
      for (k = 0; k <= t; k++)
        if (k * c[j] <= i) {
          temp = max(temp, dp[i - k * c[j]][j - 1] + k * d[j]);
        }
      dp[i][j] = temp;
    }
  }
  int Max = -1;
  for (int l = 0; l <= n; l++) {
    Max = max(Max, dp[l][m] + ((n - l) / x) * y);
  }
  cout << Max << endl;
  return 0;
}
