#include <bits/stdc++.h>
using namespace std;
long section[2100], price[2100];
int main() {
  long n, m, l, r, t, c, i, j;
  long long s;
  while (cin >> n >> m) {
    for (i = 1; i <= n; i++) section[i] = 9999;
    for (i = 0; i < m; i++) {
      cin >> l >> r >> t >> c;
      for (j = l; j <= r; j++)
        if (t < section[j]) {
          section[j] = t;
          price[j] = c;
        }
    }
    s = 0;
    for (i = 1; i <= n; i++)
      if (section[i] != 9999) s += price[i];
    cout << s << endl;
  }
}
