#include <bits/stdc++.h>
using namespace std;
int max_c[200];
int max_t[200];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < 200; i++) {
    max_t[i] = 20000;
    max_c[i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    int l, r, c, t;
    cin >> l >> r >> t >> c;
    for (int i = l; i <= r; i++) {
      if (max_t[i] < t) continue;
      if (max_t[i] > t) {
        max_c[i] = c;
        max_t[i] = t;
        continue;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += max_c[i];
  cout << ans;
}
