#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int i, l[m], r[m], t[m], c[m];
  for (i = 0; i < m; i++) cin >> l[i] >> r[i] >> t[i] >> c[i];
  int ans = 0;
  for (i = 1; i <= n; i++) {
    int p = 0, q = 0;
    for (int j = 0; j < m; j++) {
      if (i >= l[j] && i <= r[j]) {
        if (p == 0 && q == 0) {
          q = t[j];
          p = c[j];
        } else {
          if (t[j] < q) {
            p = c[j];
            q = t[j];
          }
        }
      }
    }
    ans += p;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) solve();
}
