#include <bits/stdc++.h>
int main() {
  int n, m, ans = 0, l[1001], r[1001], t[1001], c[1001];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d %d", &l[i], &r[i], &t[i], &c[i]);
  }
  int j1[n];
  for (int i = 1; i <= n; i++) j1[i] = -1;
  for (int i = 1; i <= n; i++) {
    int max = 0;
    int min = 10000;
    for (int j = 0; j < m; j++) {
      if (l[j] <= i && r[j] >= i) {
        if (t[j] < min) {
          min = t[j];
          max = c[j];
          j1[i] = j;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++)
    if (j1[i] != -1) ans += c[j1[i]];
  printf("%d", ans);
  return 0;
}
