#include <bits/stdc++.h>
using namespace std;
int marks[102];
int pro[102];
int main() {
  int n, m;
  while (cin >> n >> m) {
    memset(marks, 0x7f, sizeof marks);
    memset(pro, 0, sizeof pro);
    int l, r, t, c;
    for (int i = 1; i <= m; i++) {
      cin >> l >> r >> t >> c;
      for (int j = l; j <= r; j++) {
        if (t < marks[j]) {
          marks[j] = t;
          pro[j] = c;
        }
      }
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
      res += pro[i];
    }
    cout << res << endl;
  }
  return 0;
}
