#include <bits/stdc++.h>
using namespace std;
struct Data {
  int begin;
  int end;
  int time;
  int win;
} data[100];
int N;
int M;
int main() {
  scanf("%d %d", &N, &M);
  for (int m = 0; m < M; m++) {
    scanf("%d %d %d %d", &data[m].begin, &data[m].end, &data[m].time,
          &data[m].win);
    data[m].begin--;
    data[m].end--;
  }
  int money = 0;
  for (int n = 0; n < N; n++) {
    int best = -1;
    for (int m = 0; m < M; m++) {
      if (data[m].begin <= n && data[m].end >= n) {
        if (best == -1) {
          best = m;
        } else if (data[m].time < data[best].time) {
          best = m;
        }
      }
    }
    if (best != -1) {
      money += data[best].win;
    }
  }
  printf("%d\n", money);
  return 0;
}
