#include <bits/stdc++.h>
using namespace std;
int botva452[1100];
int val[1100];
int main() {
  int n, m;
  cin >> n >> m;
  memset(botva452, -1, sizeof(botva452));
  memset(val, 0, sizeof(val));
  for (int i = 0; i < m; i++) {
    int l, r, t, c;
    cin >> l >> r >> t >> c;
    --l, --r;
    for (int j = l; j <= r; j++) {
      if (botva452[j] == -1 || botva452[j] > t) {
        botva452[j] = t;
        val[j] = c;
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < n; i++) sum += val[i];
  cout << sum << endl;
  return 0;
}
