#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int N = 15;
int n, m, c0, d0;
int a[N], b[N], c[N], d[N];
int memo[15][1005][105];
int max(int a, int b, int c) { return max(a, max(b, c)); }
int solve(int i, int dough, int current) {
  if (i == m) {
    return 0;
  }
  int &ret = memo[i][dough][current];
  if (~ret) return ret;
  int ch1 = 0, ch2 = 0, ch3 = 0;
  if (current - b[i] >= 0 && dough - c[i] >= 0)
    ch1 = d[i] + solve(i, dough - c[i], current - b[i]);
  ch2 = solve(i + 1, dough, a[i + 1]);
  if (dough - c0 >= 0) ch3 = d0 + solve(i, dough - c0, current);
  return ret = max(ch1, ch2, ch3);
}
int main() {
  memset(memo, -1, sizeof memo);
  cin >> n >> m >> c0 >> d0;
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  cout << solve(0, n, a[0]) << endl;
  return 0;
}
