#include <bits/stdc++.h>
using namespace std;
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int l[105], r[105], t[105], c[105], ans, mx, id;
int main() {
  int n, m;
  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]);
  for (int j = 1; j <= n; j++) {
    mx = 1e9;
    id = -1;
    for (int i = 0; i < m; i++) {
      if (l[i] <= j && j <= r[i] && t[i] < mx) {
        mx = t[i];
        id = i;
      }
    }
    if (~id) ans += c[id];
  }
  printf("%d\n", ans);
}
