#include <bits/stdc++.h>
using namespace std;
struct Node {
  int l, r, c, t, o;
} P[110], D[110];
int N, M, Ans, m, maxs, tmp;
bool B[110];
bool cmp(Node A, Node B) { return A.t < B.t || (A.t == B.t && A.o < B.o); }
int main() {
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    cin >> P[i].l >> P[i].r >> P[i].t >> P[i].c;
    P[i].o = i;
  }
  sort(P + 1, P + M + 1, cmp);
  for (int i = 1; i <= N; i++) D[i].t = 0x7ffffff;
  Ans = 0;
  for (int i = 1; i <= M; i++) {
    m = -0x7ffffff;
    maxs = 0;
    for (int j = 1; j <= M; j++)
      if (!B[j]) {
        tmp = 0;
        for (int k = P[j].l; k <= P[j].r; k++)
          if (P[j].t < D[k].t || (P[j].t == D[k].t && P[j].o < D[k].o))
            tmp = tmp + P[j].c - D[k].c;
        Ans += tmp;
        maxs = j;
        B[maxs] = 1;
        for (int k = P[maxs].l; k <= P[maxs].r; k++) D[k] = P[maxs];
      }
  }
  cout << Ans << endl;
}
