#include <bits/stdc++.h>
using namespace std;
int n, m;
int menort[128], ganho[128];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    menort[i] = 0x3f3f3f3f;
    ganho[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b, t, c;
    scanf("%d %d %d %d", &a, &b, &t, &c);
    a--;
    b--;
    for (int j = a; j <= b; j++)
      if (t < menort[j]) {
        menort[j] = t;
        ganho[j] = c;
      }
  }
  int tot = 0;
  for (int i = 0; i < n; i++) tot += ganho[i];
  printf("%d\n", tot);
  return 0;
}
