#include <bits/stdc++.h>
using namespace std;
int d[105], v[105];
int main() {
  int n, m, x, y, tim, c, i, j;
  while (cin >> n >> m) {
    for (i = 1; i <= n; i++) v[i] = 100000, d[i] = 0;
    for (i = 1; i <= m; i++) {
      scanf("%d%d%d%d", &x, &y, &tim, &c);
      for (j = x; j <= y; j++) {
        if (tim < v[j]) {
          v[j] = tim;
          d[j] = c;
        }
      }
    }
    int sum = 0;
    for (i = 1; i <= n; i++) sum += d[i];
    cout << sum << endl;
  }
}
