#include <bits/stdc++.h>
struct Astro {
  int start, end, time, bet;
};
int main() {
  struct Astro input[1000];
  int n, l;
  int counter, counterY;
  int min;
  struct Astro *p;
  int ans = 0;
  scanf("%d%d", &n, &l);
  for (counter = 0; counter < l; counter++) {
    scanf("%d%d%d%d", &input[counter].start, &input[counter].end,
          &input[counter].time, &input[counter].bet);
  }
  for (counter = 1; counter <= n; counter++) {
    min = INT_MAX;
    p = NULL;
    for (counterY = 0; counterY < l; counterY++) {
      if (input[counterY].start <= counter && counter <= input[counterY].end) {
        if (min > input[counterY].time) {
          min = input[counterY].time;
          p = &input[counterY];
        }
      }
    }
    if (p != NULL) {
      ans += p->bet;
    }
  }
  printf("%d\n", ans);
  return 0;
}
