#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, l, r, t, s, uchtime[500], sum[500], n, m;
  for (i = 0; i < 500; i++) {
    uchtime[i] = 1000000000;
    sum[i] = 0;
  }
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> l >> r >> t >> s;
    for (j = l; j <= r; j++) {
      if (uchtime[j] > t) {
        uchtime[j] = t;
        sum[j] = s;
      }
    }
  }
  int ans = 0;
  for (i = 1; i <= n; i++) {
    ans = ans + sum[i];
  }
  cout << ans;
  cin.get();
  cin.get();
}
