#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
const int INF = 1e9;
struct Node {
  int l, r, t, c;
} sec[maxn];
int win[maxn], loc[maxn];
int main() {
  int i, j, n, m, ans = 0;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) win[i] = INF;
  for (i = 1; i <= m; i++) {
    scanf("%d %d %d %d", &sec[i].l, &sec[i].r, &sec[i].t, &sec[i].c);
    for (j = sec[i].l; j <= sec[i].r; j++) {
      if (sec[i].t < win[j]) {
        win[j] = sec[i].t;
        loc[j] = i;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if (loc[i]) {
      ans += sec[loc[i]].c;
    }
  }
  printf("%d\n", ans);
  return 0;
}
