#include <bits/stdc++.h>
using namespace std;
int n, m;
const int inf = 1000 * 1000 * 1000;
int L[1000], R[1000], T[1000], C[1000];
int Time[1000];
int main() {
  for (int i = 0; i < 1000; ++i) Time[i] = inf;
  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]);
    L[i]--;
    R[i]--;
  }
  int res = 0, t;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (L[j] <= i && i <= R[j]) Time[i] = min(Time[i], T[j]);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      t = 0;
      if (L[j] <= i && i <= R[j] && Time[i] == T[j]) {
        t = C[j];
        break;
      }
    }
    res += t;
  }
  printf("%d\n", res);
  return 0;
}
