#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, l, r, c, t, i, j, ans;
  pair<int, int> a[200];
  cin >> n >> m;
  for (i = 1; i <= n; ++i) a[i].first = 10000;
  for (i = 1; i <= m; ++i) {
    cin >> l >> r >> t >> c;
    for (j = l; j <= r; ++j)
      if (a[j].first > t) {
        a[j].first = t;
        a[j].second = c;
      }
  }
  ans = 0;
  for (i = 1; i <= n; ++i) {
    if (a[i].first < 10000) ans += a[i].second;
  }
  cout << ans << endl;
  return 0;
}
