#include <bits/stdc++.h>
int win[101], mint[101];
int main() {
  int n, m, i, a, b, c, d, ans = 0;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) mint[i] = 1 << 28;
  while (m--) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    for (i = a; i <= b; i++) {
      if (mint[i] > c) {
        mint[i] = c;
        win[i] = d;
      }
    }
  }
  for (i = 1; i <= n; i++) ans += win[i];
  printf("%d\n", ans);
  return 0;
}
