#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, sum = 0;
  ;
  cin >> n >> m;
  int l[m + 1], r[m + 1], c[m + 1], t[m + 1];
  for (long long int i = 1; i <= m; i++) cin >> l[i] >> r[i] >> t[i] >> c[i];
  vector<long long int> v, w;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (l[j] <= i && r[j] >= i) v.push_back(j);
    }
    if (!v.empty()) {
      sort(v.begin(), v.end(), greater<int>());
      int mi = 1000, k = -1;
      for (int j = 0; j < v.size(); j++) {
        if (mi >= t[v[j]]) {
          mi = t[v[j]];
          k = v[j];
        }
      }
      if (k != -1) sum += c[k];
      k = -1;
      mi = 1000;
      v.clear();
    }
  }
  cout << sum;
  return 0;
}
