#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> l(m), r(m), t(m), c(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d%d", &l[i], &r[i], &t[i], &c[i]);
  }
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    int mn = 10000;
    int mnj = -1;
    for (int j = 0; j < m; ++j) {
      if (l[j] <= i && i <= r[j]) {
        if (t[j] < mn) {
          mnj = j;
          mn = t[j];
        }
      }
    }
    if (mnj != -1) {
      res += c[mnj];
    }
  }
  printf("%d\n", res);
  return 0;
}
