#include <bits/stdc++.h>
struct node {
  int l, r, t, c;
} p[102];
int main() {
  int n, m, i, j, s;
  while (~scanf("%d%d", &n, &m)) {
    s = 0;
    for (i = 0; i < m; i++)
      scanf("%d%d%d%d", &p[i].l, &p[i].r, &p[i].t, &p[i].c);
    for (i = 1; i <= n; i++) {
      int min = 1002, r = 0;
      for (j = 0; j < m; j++) {
        if (p[j].l <= i && p[j].r >= i) {
          if (p[j].t < min) {
            min = p[j].t;
            r = p[j].c;
          }
        }
      }
      s += r;
    }
    printf("%d\n", s);
  }
  return 0;
}
