#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, l, r, a[105], k[105], t[105], i, j, p = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++) a[i] = 0;
  for (i = 1; i <= m; i++) {
    cin >> l >> r >> t[i] >> k[i];
    for (j = l; j <= r; j++) {
      if (!a[j] || t[i] < t[a[j]]) a[j] = i;
    }
  }
  k[0] = 0;
  for (i = 1; i <= n; i++) {
    p += k[a[i]];
  }
  cout << p;
  return 0;
}
