#include <bits/stdc++.h>
using namespace std;
long long n, m, c0, d0;
vector<pair<pair<long long, long long>, long long>> v;
long long dp[1005][15];
long long solve(long long dough, long long current) {
  if (dough < 0) return INT_MIN;
  if (current == m) return 0;
  long long &ans = dp[dough][current];
  if (ans != -1) return ans;
  for (long long i = 0; i <= v[current].first.first; i++) {
    ans = max(ans, solve(dough - i * v[current].first.second, current + 1) +
                       i * v[current].second);
  }
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0);
  ;
  memset(dp, -1, sizeof(dp));
  cin >> n >> m >> c0 >> d0;
  for (long long i = 0; i < m; i++) {
    long long a1, b1, c1, d1;
    cin >> a1 >> b1 >> c1 >> d1;
    b1 = a1 / b1;
    v.emplace_back(make_pair(make_pair(b1, c1), d1));
  }
  long long ans = 0;
  for (long long i = 0; i <= n / c0; i++) {
    long long temp = i * d0;
    temp = max(temp, temp + solve(n - i * c0, 0));
    ans = max(ans, temp);
  }
  cout << ans;
}
