#include <bits/stdc++.h>
using namespace std;
struct B {
  int l, r, t, c;
} a[130];
int b[130], t[130], c[130];
int main() {
  int i, j, n, m;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; ++i)
    scanf("%d %d %d %d", &a[i].l, &a[i].r, &a[i].t, &a[i].c);
  for (i = 0; i <= n; ++i) t[i] = 1000000000;
  memset(c, 0, sizeof(c));
  for (i = 0; i < m; ++i)
    for (j = a[i].l; j <= a[i].r; ++j)
      if (t[j] > a[i].t) {
        t[j] = a[i].t;
        c[j] = a[i].c;
      }
  int s = 0;
  for (i = 0; i <= n; ++i) s += c[i];
  printf("%d", s);
}
