#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
const int N = 1e3 + 10, M = 110, OOm = 0x3f3f3f3f;
string blank = "";
int n, m, c0, d0;
struct data {
  int a, b, c, d;
} arr[20];
int dp[N][15];
int rec(int dough, int j) {
  if (dough <= 0 || j > m) return 0;
  int &ans = dp[dough][j];
  if (~ans) return ans;
  for (int i = 0;; i++) {
    if (arr[j].a / arr[j].b >= i && dough / arr[j].c >= i) {
      ans = max(ans, rec(dough - arr[j].c * i, j + 1) + arr[j].d * i);
    } else
      break;
  }
  return ans;
}
void solve() {
  for (int i = 0; i < N; i++) memset(dp[i], -1, sizeof dp[i]);
  cin >> n >> m >> arr[0].c >> arr[0].d;
  arr[0].a = n;
  arr[0].b = arr[0].c;
  for (int i = 1; i <= m; i++) {
    cin >> arr[i].a >> arr[i].b >> arr[i].c >> arr[i].d;
  }
  cout << rec(n, 0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl;
}
