#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 5;
struct Node {
  int t;
  int c;
} node[MAX];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    node[i].t = 1e7;
    node[i].c = 0;
  }
  int l, r, t, c;
  for (int i = 0; i < m; i++) {
    cin >> l >> r >> t >> c;
    for (int j = l; j <= r; j++) {
      if (t < node[j].t) {
        node[j].c = c;
        node[j].t = t;
      }
    }
  }
  int total = 0;
  for (int i = 1; i <= n; i++) {
    total += node[i].c;
  }
  cout << total << endl;
  ;
  return 0;
}
