#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n + 1], c[n + 1], s = 0;
  for (int i = 1; i <= n; i++) a[i] = 2000;
  while (m--) {
    int l, r, t, cst;
    cin >> l >> r >> t >> cst;
    for (int i = l; i <= r; i++) {
      if (a[i] > t) a[i] = t, c[i] = cst;
    }
  }
  for (int i = 1; i <= n; i++)
    if (a[i] != 2000) s += c[i];
  cout << s;
}
