#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int l[N], r[N], t[N], c[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d %d", l + i, r + i, t + i, c + i);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int win = 0, min = -1;
    for (int j = 0; j < m; ++j) {
      if (l[j] <= i && i <= r[j]) {
        if (min == -1 || min > t[j]) {
          min = t[j];
          win = c[j];
        }
      }
    }
    ans += win;
  }
  printf("%d\n", ans);
  return 0;
}
