#include <bits/stdc++.h>
using namespace std;
struct Node {
  int l, r, t, c, index;
} man[101];
int flag[101];
bool cmp(Node a, Node b) {
  if (a.t < b.t) return true;
  if (a.t > b.t) return false;
  if (a.t == b.t) return a.index < b.index;
}
int main() {
  int n, m, ans, i, j, tmp;
  while (cin >> n >> m) {
    memset(flag, 0, sizeof(flag));
    ans = 0;
    for (i = 0; i < m; i++) {
      cin >> man[i].l >> man[i].r >> man[i].t >> man[i].c;
      man[i].index = i;
    }
    sort(man, man + m, cmp);
    for (i = 0; i < m; i++) {
      for (j = man[i].l; j <= man[i].r; j++) {
        if (flag[j] == 0) {
          flag[j] = 1;
          ans += man[i].c;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
