#include <bits/stdc++.h>
using namespace std;
using vll = vector<long long>;
long long mod = 1000000007;
long long modu(long long a, long long b) {
  long long c = a % b;
  return (c < 0) ? c + b : c;
}
long long ipow(long long a, long long b, long long m) {
  long long ans = 1;
  while (b--) {
    ans = ans * a;
    ans %= m;
  }
  return ans;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void solve() {
  long long n, m, d0, c0;
  cin >> n >> m >> c0 >> d0;
  long long a[m + 1], b[m + 1], c[m + 1], d[m + 1];
  for (long long i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  long long dp[n + 1][m + 1];
  memset(dp, 0, sizeof(dp));
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      for (long long num = 0; num <= a[j] / b[j]; num++) {
        if (i - num * c[j] >= 0)
          dp[i][j] = max(dp[i - num * c[j]][j - 1] + num * d[j], dp[i][j]);
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i <= n; i++) {
    ans = max(ans, dp[i][m] + ((n - i) / c0) * d0);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tc = 1;
  while (tc--) {
    solve();
  }
}
