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