#include <bits/stdc++.h>
using namespace std;
int m, c0, d0;
vector<int> a(11), b(11), c(11), d(11);
int main() {
  int n;
  scanf("%d %d %d %d", &n, &m, &c0, &d0);
  a[0] = n, b[0] = 0, c[0] = c0, d[0] = d0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
  }
  vector<int> dp(n + 1);
  int rs = 0;
  for (int i = 0; i <= m; i++) {
    for (int j = n; j >= 0; j--) {
      for (int u = 0; j - u * c[i] >= 0 && u * b[i] <= a[i]; u++) {
        int nu = j - u * c[i];
        dp[j] = max(dp[j], dp[nu] + u * d[i]);
        rs = max(rs, dp[j]);
      }
    }
  }
  printf("%d\n", rs);
}
