#include <bits/stdc++.h>
int main() {
  static int ii[100], tt[100], cc[100];
  int n, m, h, i, l, r, sum;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) ii[i] = -1;
  for (h = 0; h < m; h++) {
    scanf("%d%d%d%d", &l, &r, &tt[h], &cc[h]);
    l--, r--;
    for (i = l; i <= r; i++)
      if (ii[i] == -1 || tt[ii[i]] > tt[h]) ii[i] = h;
  }
  sum = 0;
  for (i = 0; i < n; i++) sum += cc[ii[i]];
  printf("%d\n", sum);
  return 0;
}
