#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9;
const int N = 2e4 + 5;
const int maxn = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const int ONF = -0x3f3f3f3f;
int main() {
  int n, g, c0, d0;
  cin >> n >> g >> c0 >> d0;
  int a[N], b[N], c[N], d[N];
  for (int i = 1; i <= g; i++) scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
  a[0] = 0;
  b[0] = 0;
  c[0] = c0;
  d[0] = d0;
  int m[N];
  memset(m, 0, sizeof(m));
  int v[N];
  memset(v, 0, sizeof(v));
  int dp[N];
  memset(dp, 0, sizeof(dp));
  int cnt = 0;
  for (int i = 1; i <= g; i++) {
    int p = a[i] / b[i];
    for (int j = 0; j < p; j++) {
      m[cnt] = c[i];
      v[cnt] = d[i];
      cnt++;
    }
  }
  int p = n / c[0];
  for (int i = 0; i < p; i++) {
    m[cnt] = c[0];
    v[cnt++] = d[0];
  }
  for (int i = 0; i < cnt; i++) {
    for (int j = n; j >= m[i]; j--) {
      dp[j] = max(dp[j], dp[j - m[i]] + v[i]);
    }
  }
  cout << dp[n] << endl;
  return 0;
}
