#include <bits/stdc++.h>
using namespace std;
const int mx = 1e6 + 10;
int n, m, l, r, t, c, ans, a[mx], b[mx];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  while (m--) {
    cin >> l >> r >> t >> c;
    for (long long int i = l; i < r + 1; i++) {
      if (t < a[i] || a[i] == 0) a[i] = t, b[i] = c;
    }
  }
  for (long long int i = 1; i < n + 1; i++) ans += b[i];
  cout << ans << endl;
  return 0;
}
