#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> l(m), r(m), t(m), c(m);
  for (int i = 0; i < m; ++i) {
    cin >> l[i] >> r[i] >> t[i] >> c[i];
  }
  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    int best = 1e8, cost = 0;
    bool was = false;
    for (int j = 0; j < m; ++j)
      if (l[j] <= i && r[j] >= i) {
        was = true;
        if (t[j] < best) {
          best = t[j];
          cost = c[j];
        }
      }
    if (was) res += cost;
  }
  cout << res << endl;
  return 0;
}
