#include <bits/stdc++.h>
using namespace std;
int dp[11][1001];
int a[11], b[11], c[11], d[11], ans = 0;
void solve() {
  int n, m, c0, d0;
  scanf("%d %d %d %d", &n, &m, &c0, &d0);
  for (int C = 0; C <= n; C++) dp[0][C] = (C / c0) * d0;
  for (int i = 1; i <= m; i++) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
  for (int M = 1; M <= m; M++) {
    for (int C = 0; C <= n; C++) {
      dp[M][C] = 0;
      for (int k = 0; k <= min(C / c[M], a[M] / b[M]); k++)
        dp[M][C] = max(dp[M][C], dp[M - 1][C - c[M] * k] + k * d[M]);
      ans = max(ans, dp[M][C]);
    }
  }
  printf("%d", max(n / c0, ans));
}
int main() {
  if (1) {
  } else {
    freopen("input.txt", "r", stdin);
  }
  solve();
  return 0;
}
