#include <bits/stdc++.h>
using namespace std;
struct Node {
  int a, b, c, d;
} x[10005];
int dp[10005];
int main() {
  int n, m, c, d;
  cin >> n >> m >> c >> d;
  for (int i = 0; i < m; i++) {
    cin >> x[i].a >> x[i].b >> x[i].c >> x[i].d;
  }
  for (int i = 0; i <= n; i++) dp[i] = (i / c) * d;
  for (int i = 0; i < m; i++) {
    for (int j = 1; j <= x[i].a / x[i].b; j++) {
      for (int k = n; k >= x[i].c; k--) {
        dp[k] = max(dp[k], dp[k - x[i].c] + x[i].d);
      }
    }
  }
  cout << dp[n];
}
