#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, c0, d0;
  cin >> n >> m >> c0 >> d0;
  int a[15];
  int b[15];
  int c[15];
  int d[15];
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  int dp[15][1005][105];
  for (int i = 0; i < 1005; i++) {
    for (int j = 0; j < 105; j++) {
      dp[0][i][j] = 0;
    }
  }
  a[0] = 0;
  b[0] = 0;
  c[0] = 0;
  d[0] = 0;
  for (int i = 1; i <= m; i++) {
    for (int dough = 0; dough <= n; dough++) {
      for (int stuffing = 0; stuffing <= a[i]; stuffing++) {
        dp[i][dough][stuffing] =
            (((dough - c[i] >= 0 && stuffing - b[i] >= 0)
                  ? (dp[i][dough - c[i]][stuffing - b[i]] + d[i])
                  : -9001) > (dp[i - 1][dough][a[i - 1]])
                 ? ((dough - c[i] >= 0 && stuffing - b[i] >= 0)
                        ? (dp[i][dough - c[i]][stuffing - b[i]] + d[i])
                        : -9001)
                 : (dp[i - 1][dough][a[i - 1]]));
      }
    }
  }
  for (int dough = 0; dough <= n; dough++) {
    dp[m + 1][dough][0] =
        (((dough - c0 >= 0) ? (dp[m + 1][dough - c0][0] + d0) : -9001) >
                 (dp[m][dough][a[m]])
             ? ((dough - c0 >= 0) ? (dp[m + 1][dough - c0][0] + d0) : -9001)
             : (dp[m][dough][a[m]]));
  }
  cout << dp[m + 1][n][0] << endl;
  return 0;
}
