#include <bits/stdc++.h>
using namespace std;
int *save, *mintime;
int main() {
  int k, m, b, start, end, time, money, sum;
  cin >> k >> m;
  save = new int[k + 1];
  mintime = new int[k + 1];
  fill(save, save + k + 1, 0);
  fill(mintime, mintime + k + 1, 0);
  for (sum = 0; m > 0; --m) {
    cin >> start >> end >> time >> money;
    for (b = start; b <= end; ++b) {
      if (time < mintime[b] || !mintime[b]) {
        mintime[b] = time;
        sum += money - save[b];
        save[b] = money;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
