#include <bits/stdc++.h>
using namespace std;
class data {
 public:
  int it, l, r, t, c;
  friend bool operator<(data A, data B) {
    return (A.t < B.t) || (A.t == B.t && A.it < B.it);
  }
};
int main() {
  int n, m;
  int i, j, k;
  vector<data> vd;
  data d;
  scanf("%d%d", &n, &m);
  vector<int> v(n + 1, 0);
  for (i = 0; i < m; i++) {
    d.it = i;
    scanf("%d%d%d%d", &d.l, &d.r, &d.t, &d.c);
    vd.push_back(d);
  }
  sort(vd.begin(), vd.end());
  int ans = 0;
  for (i = 0; i < vd.size(); i++) {
    d = vd[i];
    for (j = d.l; j <= d.r; j++) {
      if (v[j] == 0) {
        v[j] = d.c;
        ans += d.c;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
