#include <bits/stdc++.h>
using namespace std;
struct com {
  int r;
  int l;
  int t;
  int c;
  int deta;
};
bool cmp1(com b, com d) { return b.t < d.t; }
bool cmp2(com b, com d) { return b.deta < d.deta; }
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    int i;
    com a[110];
    memset(a, 0, sizeof(a));
    for (i = 1; i <= m; i++) {
      scanf("%d", &a[i].l);
      scanf("%d", &a[i].r);
      scanf("%d", &a[i].t);
      scanf("%d", &a[i].c);
      a[i].deta = i;
    }
    sort(a + 1, a + 1 + m, cmp1);
    int count[110] = {0};
    int h = 0, ok = 0, op = 0;
    for (i = 1; i < m; i++) {
      if (a[i].t == a[i + 1].t) {
        if (ok == 0) {
          ok = 1;
          op = i;
          h = 2;
        } else
          h++;
      }
      if ((a[i].t != a[i + 1].t) && ok == 1) {
        sort(a + op, a + op + h, cmp2);
        ok = 0;
      }
    }
    int j, max = 0;
    for (i = 1; i <= m; i++) {
      for (j = a[i].l; j <= a[i].r; j++) {
        if (count[j] == 0) {
          max = a[i].c + max;
          count[j] = 1;
        }
      }
    }
    printf("%d\n", max);
  }
  return 0;
}
