#include <bits/stdc++.h>
using namespace std;
long long i, j, k, n, m, l[105], r[105], t[105], c[105], ans, mintime, profit;
int main() {
  cin >> n >> m;
  for (i = 0; i < m; ++i) cin >> l[i] >> r[i] >> t[i] >> c[i];
  for (i = 1; i < n + 1; ++i) {
    mintime = 1000000;
    profit = 0;
    for (j = 0; j < m; ++j) {
      if (i >= l[j] && i <= r[j]) {
        if (mintime > t[j]) {
          mintime = t[j];
          profit = c[j];
        }
      }
    }
    ans += profit;
  }
  cout << ans;
}
