#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int main() {
  int n, m, l, r, t, c;
  cin >> n >> m;
  pair<int, int> s[n + 1];
  for (int i = (1), _b = (n + 1); i < (_b); ++i) s[i] = make_pair(0, 0);
  for (int i = (0), _b = (m); i < (_b); ++i) {
    cin >> l >> r >> t >> c;
    for (int j = (l), _b = (r + 1); j < (_b); ++j) {
      if (!s[j].second)
        s[j] = make_pair(t, c);
      else {
        if (t < s[j].first) {
          s[j] = make_pair(t, c);
        }
      }
    }
  }
  int ret = 0;
  for (int i = (1), _b = (n + 1); i < (_b); ++i) {
    ret += s[i].second;
  }
  cout << ret << endl;
  return 0;
}
