#include <bits/stdc++.h>
#pragma comment(linker, "/stack:336777216")
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll const mod = 1000000007;
int dp[1005][15] = {};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int n, m, c0, d0;
  cin >> n >> m >> c0 >> d0;
  vector<tuple<int, int, int, int>> v;
  v.push_back({-1, -1, c0, d0});
  for (int i = 0; i < m; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    v.push_back({a, b, c, d});
  }
  for (int i = 0; i <= n; i += c0) dp[i][0] = (i / c0) * d0;
  for (int j = 0; j < m; j++) {
    for (int i = 0; i <= n; i++) {
      int a, b, c, d;
      tie(a, b, c, d) = v[j + 1];
      int canmake = min((n - i) / c, a / b);
      for (int k = 0; k <= canmake; k++) {
        dp[i + k * c][j + 1] = max(dp[i + k * c][j + 1], dp[i][j] + k * d);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) ans = max(ans, dp[i][m]);
  cout << ans << '\n';
  return 0;
}
