#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n, m, l, r, ti, c;
  vector<int> t, s;
  cin >> n >> m;
  t.resize(n + 2, 10000);
  s.resize(n + 2, 0);
  for (i = 0; i < m; i++) {
    cin >> l >> r >> ti >> c;
    for (j = l; j <= r; j++) {
      if (t[j] > ti) {
        t[j] = ti;
        s[j] = c;
      }
    }
  }
  for (i = 1; i <= n; i++) s[0] = s[0] + s[i];
  cout << s[0];
}
