#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
template <typename Arg1>
void trace(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void trace(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
template <typename Arg1>
void pr(const char* name, Arg1&& arg1) {
  cout << arg1 << endl;
}
template <typename Arg1, typename... Args>
void pr(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout << arg1 << " ";
  pr(comma + 1, args...);
}
void printV(vector<int>& arr) {
  cout << "Vector : ";
  if (arr.empty()) {
    cout << endl;
    return;
  }
  for (int i = 0; i < arr.size(); i++)
    cout << arr[i] << " \n"[i == arr.size() - 1];
}
void printA(int* arr, int n, int start = 0) {
  cout << "Array : ";
  if (!n) {
    cout << endl;
    return;
  }
  for (int i = start; i < n; i++) cout << arr[i] << " \n"[i == n - 1];
}
void printV(vector<long long>& arr) {
  cout << "Vector : ";
  if (arr.empty()) {
    cout << endl;
    return;
  }
  for (int i = 0; i < arr.size(); i++)
    cout << arr[i] << " \n"[i == arr.size() - 1];
}
void printA(int arr[], int n) {
  cout << "Array : ";
  if (!n) {
    cout << endl;
    return;
  }
  for (int i = 0; i < n; i++) cout << arr[i] << " \n"[i == n - 1];
}
const int N = 1100;
int n, m, c, d;
int A[N], B[N], C[N], D[N];
int dp[N][N];
int find(int rem, int pos) {
  if (rem < 0) return -1e5;
  if (pos > m + 1) return 0;
  int& ans = dp[rem][pos];
  if (ans != -1) return ans;
  ans = 0;
  for (int mk = 0; mk <= min(rem / C[pos], A[pos] / B[pos]); mk++) {
    ans = max(ans, mk * D[pos] + find(rem - C[pos] * mk, pos + 1));
  }
  return ans;
}
void solve(int tc = 1) {
  memset(dp, -1, sizeof dp);
  cin >> n >> m >> c >> d;
  for (int i = 1; i <= m; i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
  }
  A[m + 1] = 1e5;
  B[m + 1] = 1;
  C[m + 1] = c;
  D[m + 1] = d;
  cout << find(n, 1) << endl;
}
int main() {
  int tt = 1;
  for (int tc = 1; tc <= tt; tc++) {
    solve(tc);
  }
}
