#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int MAX = 2 * 1000 + 10;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
long long n, m, x, y, a[MAX], b[MAX], c[MAX], d[MAX];
long long dp[MAX][20];
long long sol(long long n, long long ind) {
  if (n < 0) return -MOD;
  if (ind > m or n == 0) return 0;
  if (dp[n][ind] != -1) return dp[n][ind];
  long long &ans = dp[n][ind];
  ans = y + sol(n - x, ind);
  for (long long i = 0; i <= n; i++) {
    if (i * c[ind] > n or i * b[ind] > a[ind]) break;
    ans = max(ans, i * d[ind] + sol(n - i * c[ind], ind + 1));
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m >> x >> y;
  for (long long i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << sol(n, 0) << '\n';
}
