#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, pair<int, int> > > stfType;
const int N = 1005;
int nn, m, c0, d0;
int DP[N][15];
int getMax(int n, int idx) {
  if (idx == m) return (n / c0) * d0;
  if (DP[n][idx] != -1) return DP[n][idx];
  int Tugriks = 0;
  for (int num = 0;
       (num * stfType[idx].first.second <= stfType[idx].first.first &&
        num * stfType[idx].second.first <= n);
       num++)
    Tugriks =
        max(Tugriks, (num * stfType[idx].second.second +
                      getMax(n - num * stfType[idx].second.first, idx + 1)));
  return DP[n][idx] = Tugriks;
}
int main() {
  cin >> nn >> m >> c0 >> d0;
  stfType.resize(m);
  for (auto &it : stfType)
    cin >> it.first.first >> it.first.second >> it.second.first >>
        it.second.second;
  memset(DP, -1, sizeof DP);
  cout << getMax(nn, 0) << endl;
  return 0;
}
