#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, e, t, r;
  cin >> n >> m;
  vector<pair<int, int> > sections(n + 1);
  for (int i = 1; i <= n; i++) sections[i].first = 0x3f3f3f3f;
  while (m--) {
    cin >> s >> e >> t >> r;
    for (int i = s; i <= e; i++) {
      if (t < sections[i].first) {
        sections[i].first = t;
        sections[i].second = r;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += sections[i].second;
  }
  cout << ans;
}
