#include <bits/stdc++.h>
using namespace std;
int matrix[1005][4], dp[15][1005], totalGrams, totalStuffings, withoutStuffing,
    moneyWithoutStuffing;
int solve(int idx, int doughLeft) {
  if (doughLeft <= 0) return 0;
  if (idx == totalStuffings)
    return (doughLeft / withoutStuffing) * moneyWithoutStuffing;
  if (dp[idx][doughLeft] != -1) return dp[idx][doughLeft];
  int ans = INT_MIN;
  for (int i = 0; i < 1000; i++) {
    if (matrix[idx][0] - i * matrix[idx][1] >= 0 &&
        doughLeft - i * matrix[idx][2] >= 0)
      ans = max(ans, matrix[idx][3] * i +
                         solve(idx + 1, doughLeft - i * matrix[idx][2]));
    else
      break;
  }
  return dp[idx][doughLeft] = ans;
}
int main(void) {
  int i;
  cin >> totalGrams >> totalStuffings >> withoutStuffing >>
      moneyWithoutStuffing;
  for (i = 0; i < totalStuffings; i++)
    cin >> matrix[i][0] >> matrix[i][1] >> matrix[i][2] >> matrix[i][3];
  memset(dp, -1, sizeof dp);
  cout << solve(0, totalGrams);
  return 0;
}
