#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, mint[101], maxc[101] = {0};
  for (int i = 0; i <= 100; i++) mint[i] = 10000;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int l, r, t, c;
    scanf("%d%d%d%d", &l, &r, &t, &c);
    for (int j = l; j <= r; j++) {
      if (t < mint[j]) {
        mint[j] = t;
        maxc[j] = c;
      }
    }
  }
  int maxout = 0;
  for (int i = 1; i <= n; i++) {
    maxout += maxc[i];
  }
  printf("%d\n", maxout);
}
