#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int n, b[110], l, r, c, t, q[110], m;
int main() {
  cin >> m >> n;
  for (int i = 1; i <= m; i++) b[i] = 1 << 30;
  for (int i = 0; i < n; i++) {
    cin >> l >> r >> t >> c;
    for (int j = l; j <= r; j++) {
      if (t < b[j]) b[j] = t, q[j] = c;
    }
  }
  int s = 0;
  for (int i = 1; i <= m; i++) {
    s += q[i];
  }
  cout << s;
  return 0;
}
