#include <bits/stdc++.h>
int main() {
  int i, l, r, t, c, sum = 0, s, p, **bets;
  scanf("%d%d", &s, &p);
  bets = (int **)calloc(s, sizeof(int *));
  for (i = 0; i < s; i++)
    bets[i] = (int *)calloc(2, sizeof(int)), bets[i][0] = 999999999;
  while (p > 0) {
    p--;
    scanf("%d%d%d%d", &l, &r, &t, &c);
    for (i = l - 1; i < r; i++)
      if (bets[i][0] > t) {
        bets[i][0] = t;
        bets[i][1] = c;
      }
  }
  for (i = 0; i < s; i++) sum += bets[i][1];
  printf("%d", sum);
  return 0;
}
