#include <bits/stdc++.h>
using namespace std;
int main() {
  int sec, pla, L, R, T, C, ar[1010], profit[1010], i, j;
  scanf("%d %d", &sec, &pla);
  memset(ar, -1, sizeof(ar));
  memset(profit, -1, sizeof(profit));
  for (j = 0; j < pla; j++) {
    scanf("%d %d %d %d", &L, &R, &T, &C);
    for (i = L; i <= R; i++) {
      if (ar[i] == -1 || ar[i] >= T) {
        if (ar[i] == T) {
          if (C > profit[i]) {
            ;
          }
        } else {
          profit[i] = C;
        }
        ar[i] = T;
      }
    }
  }
  int sum = 0;
  for (i = 1; i <= sec; i++) {
    if (profit[i] != -1) {
      sum += profit[i];
    }
  }
  printf("%d\n", sum);
}
