#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  int time[101], profit[101] = {0};
  int n, m, res = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) time[i] = (int)2e9;
  for (int x = 1; x <= m; x++) {
    int l, r, t, c;
    scanf("%d%d%d%d", &l, &r, &t, &c);
    for (int i = l; i <= r; i++)
      if (time[i] > t) time[i] = t, profit[i] = c;
  }
  for (int i = 1; i <= n; i++) res += profit[i];
  printf("%d\n", res);
  return 0;
}
