#include <bits/stdc++.h>
using namespace std;
int tmax = 9999999;
int C[101], T[101];
int i, j, n, m, a, b, t, c;
long long ans;
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) T[i] = tmax;
  for (i = 1; i <= m; i++) {
    cin >> a >> b >> t >> c;
    for (j = a; j <= b; j++)
      if (t < T[j]) {
        T[j] = t;
        C[j] = c;
      }
  }
  for (i = 1; i <= n; i++) ans = ans + C[i];
  cout << ans << endl;
}
