#include <bits/stdc++.h>
using namespace std;
int dp[15][1004], a[102], b[102], c[102], d[102];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, c0, d0;
  cin >> n >> m >> c0 >> d0;
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  for (int pos = 1; pos <= m; pos++) {
    for (int dough = 0; dough <= n; dough++) {
      for (int x = 0; x <= 100; x++)
        for (int y = 0; y <= 100; y++) {
          if (dough >= x * c[pos] + y * c0 and a[pos] >= x * b[pos])
            dp[pos][dough] =
                max(dp[pos][dough], dp[pos - 1][dough - x * c[pos] - y * c0] +
                                        x * d[pos] + y * d0);
        }
    }
  }
  cout << dp[m][n] << endl;
  return 0;
}
