#include <bits/stdc++.h>
using namespace std;
const int INF = 10000;
struct dude {
  int l, r, t, c;
} a[105];
struct mintime {
  int mint, in;
} used[105];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i)
    scanf("%d%d%d%d", &a[i].l, &a[i].r, &a[i].t, &a[i].c);
  for (int i = 0; i < n; ++i) used[i].mint = INF;
  for (int i = 0; i < m; ++i)
    for (int j = a[i].l - 1; j < a[i].r; ++j)
      if (used[j].mint > a[i].t) {
        used[j].mint = a[i].t;
        used[j].in = i;
      }
  int ans = 0;
  for (int i = 0; i < n; ++i)
    if (used[i].mint != INF) ans += a[used[i].in].c;
  printf("%d\n", ans);
  return 0;
}
