#include <bits/stdc++.h>
using namespace std;
long long int n, m, c0, d0;
long long int dp[11][1005];
long long int a[100005], b[100005], c[100005], d[100005];
long long int find(long long int pos, long long int val) {
  if (pos > m) return (val / c0) * d0;
  if (dp[pos][val] != -1) return dp[pos][val];
  long long int ans = find(pos + 1, val);
  for (int i = 1;; i++) {
    if (val >= c[pos] * i and a[pos] >= b[pos] * i)
      ans = max(ans, d[pos] * i + find(pos + 1, val - c[pos] * i));
    else
      break;
  }
  return dp[pos][val] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  for (int i = 0; i <= 10; i++) {
    for (int j = 0; j <= 1000; j++) dp[i][j] = -1;
  }
  cin >> n >> m >> c0 >> d0;
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  cout << find(1, n) << '\n';
  return 0;
}
