#include <bits/stdc++.h>
using namespace std;
const int NN = 1000 * 1000 + 100, MAX_N = 111, MaxVal = 1000 * 1000 + 10;
long long max(long long a, long long b) { return a > b ? a : b; }
int l[111], r[111], c[111], t[111];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> t[i] >> c[i];
  }
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    int I = -1;
    for (int j = 0; j < m; j++) {
      if (l[j] <= i && i <= r[j]) {
        if (I == -1)
          I = j;
        else {
          int X = max(l[I], l[j]);
          if ((i - X + 1) * t[I] > (i - X + 1) * t[j]) {
            I = j;
          }
        }
      }
    }
    if (I != -1) {
      ans += c[I];
    }
  }
  cout << ans << endl;
}
