#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000 + 10;
const int MAX_M = 10 + 5;
int DP[MAX_N];
int N, M, C0, D0;
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M >> C0 >> D0;
  for (int i = 0; i <= N; i++) DP[i] = (i / C0) * D0;
  for (int i = 1; i <= M; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int j = N; j >= 0; j--)
      for (int i = b; i <= a; i += b)
        if (j >= c * (i / b))
          DP[j] = max(DP[j], DP[j - c * (i / b)] + (i / b) * d);
  }
  cout << DP[N] << endl;
  return 0;
}
