#include <bits/stdc++.h>
using namespace std;
struct _node {
  int time;
  int cost;
} node[110];
void add(int a, int b, int c, int d) {
  for (int i = a; i <= b; i++) {
    if (node[i].time > c || !node[i].time) {
      node[i].time = c;
      node[i].cost = d;
    }
  }
}
int main() {
  int m, n;
  while (~scanf("%d %d", &n, &m)) {
    memset(node, 0, sizeof(node));
    int a, b, c, d;
    for (int i = 0; i < m; i++) {
      scanf("%d %d %d %d", &a, &b, &c, &d);
      add(a, b, c, d);
    }
    int s = 0;
    for (int i = 1; i <= n; i++) {
      s += node[i].cost;
    }
    printf("%d\n", s);
  }
}
