#include <bits/stdc++.h>
using namespace std;
int n, m;
int l[1003], r[1003], t[1003], c[1003];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> l[i] >> r[i] >> t[i] >> c[i];
    l[i]--;
    r[i]--;
  }
  int sum = 0;
  for (int step = 0; step < n; ++step) {
    int pos = -1;
    for (int i = 0; i < m; ++i) {
      if (l[i] <= step && step <= r[i]) {
        if (pos == -1) pos = i;
        if (t[i] < t[pos]) pos = i;
      }
    }
    if (pos != -1) sum += c[pos];
  }
  cout << sum << endl;
  return 0;
}
