#include <bits/stdc++.h>
using namespace std;
vector<tuple<int, int, int, int, int, int>> stuffing;
int cmp(const tuple<int, int, int, int, int, int> &a,
        const tuple<int, int, int, int, int, int> &b) {
  return (get<5>(a) == get<5>(b)) ? (get<4>(a) < get<4>(b))
                                  : (get<5>(a) > get<5>(b));
}
int m;
int dp[20][1010];
int rec(int idx, int lot) {
  if (idx == m + 1 || lot == 0) {
    return 0;
  }
  if (dp[idx][lot] != -1) return dp[idx][lot];
  int det = get<0>(stuffing[idx]) / get<1>(stuffing[idx]);
  int mx = 0;
  int c = get<2>(stuffing[idx]);
  int d = get<3>(stuffing[idx]);
  for (int i = 0; i <= det; i++) {
    if (lot - c * i >= 0) mx = max(mx, d * i + rec(idx + 1, lot - c * i));
  }
  dp[idx][lot] = mx;
  return dp[idx][lot];
}
int main() {
  int n, c0, d0;
  cin >> n >> m >> c0 >> d0;
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 1010; j++) dp[i][j] = -1;
  }
  for (int i = 0; i < m; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int det = a / b;
    stuffing.push_back(make_tuple(a, b, c, d, c * det, d * det));
  }
  stuffing.push_back(make_tuple(n, c0, c0, d0, (n / c0) * c0, (n / c0) * d0));
  sort(stuffing.begin(), stuffing.end(), cmp);
  for (int i = 0; i < stuffing.size(); i++) {
  }
  int income = rec(0, n);
  cout << income << endl;
  return 0;
}
