#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const int M = 1e1 + 5;
const int N = 1e3 + 5;
int n, m, a[M], b[M], c[M], d[M], dp[M][N];
int solve(int i, int n) {
  if (i > m) {
    if (n <= 0) return 0;
    return d[0] * (n / c[0]);
  }
  if (dp[i][n] != -1) return dp[i][n];
  int ans = 0;
  if (n >= c[0]) ans = max(ans, solve(i + 1, n - c[0]) + d[0]);
  for (int j = 0; j <= min(a[i] / b[i], n / c[i]); j++) {
    ans = max(ans, solve(i + 1, n - j * c[i]) + j * d[i]);
  }
  return dp[i][n] = ans;
}
void code() {
  cin >> n >> m >> c[0] >> d[0];
  vector<pair<int, pair<int, pair<int, int>>>> v;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << solve(1, n) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  while (t-- > 0) {
    code();
  }
}
