#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int l, r, t, c;
  int res = 0;
  cin >> n >> m;
  n++;
  int a[n];
  int b[n];
  for (int i = 0; i < n; i++) {
    a[i] = 10000;
    b[i] = 0;
  }
  while (m--) {
    cin >> l >> r >> t >> c;
    for (int i = l; i <= r; i++) {
      if (a[i] > t) {
        a[i] = t;
        b[i] = c;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    res += b[i];
  }
  cout << res << endl;
  return 0;
}
