#include <bits/stdc++.h>
using namespace std;
int n, m;
int T[120];
int P[120];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    T[i] = 1000000;
    P[i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    int l, r, t, c;
    cin >> l >> r >> t >> c;
    for (int j = l; j <= r; j++) {
      if (T[j] > t) {
        T[j] = t;
        P[j] = c;
      }
    }
  }
  int answer = 0;
  for (int i = 1; i <= n; i++) answer += P[i];
  printf("%d\n", answer);
}
