#include <bits/stdc++.h>
using namespace std;
long long int prime = 998244353;
long long int modulo = 1e9 + 7;
const long long int inf = 1e18 + 7;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
long long int dp[1005][15];
long long int a[15], b[15], c[15], d[15];
long long int n, m, cc, dd;
void solve() {
  unordered_map<string, int> look_up;
  unordered_map<long long int, vector<int> > lp;
  long long int ans = 0;
  memset(dp, 0, sizeof(dp));
  cin >> n >> m >> cc >> dd;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  for (int i = 1; i <= m; i++) {
    int k = a[i] / b[i];
    for (int j = 1; j <= n; j++) {
      for (int x = 0; x <= k; x++) {
        if (j - x * c[i] >= 0) {
          dp[j][i] = max(dp[j][i],
                         max(dp[j][i - 1], dp[j - x * c[i]][i - 1] + x * d[i]));
        }
      }
    }
  }
  int k = n / cc;
  for (int i = 0; i <= k; i++) {
    ans = max(ans, dp[n - (i * cc)][m] + i * dd);
  }
  cout << ans;
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  solve();
  return 0;
}
