#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k, l, arr_size = 0, total = 0, min_t;
  cin >> n >> m;
  int s[m], f[m], t[m], bet[m], comp[m];
  for (i = 0; i < m; i++) {
    cin >> s[i] >> f[i] >> t[i] >> bet[i];
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < m; j++) {
      for (k = s[j]; k <= f[j]; k++) {
        if (k == i) {
          comp[arr_size++] = j;
          break;
        }
      }
    }
    if (arr_size != 0) {
      min_t = comp[0];
      for (l = 1; l < arr_size; l++) {
        if (t[comp[l]] < t[min_t]) {
          min_t = comp[l];
        }
      }
      total += bet[min_t];
      arr_size = 0;
    }
  }
  cout << total << endl;
  return 0;
}
