#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, l, r, t, ans, a[101], b[101], c[101];
int main() {
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> l >> r >> t >> c[i];
    for (j = l; j <= r; j++)
      if (a[j] == 0 || a[j] > t) {
        a[j] = t;
        b[j] = i;
      }
  }
  for (i = 1; i <= n; i++) ans += c[b[i]];
  cout << ans << endl;
}
