#include <bits/stdc++.h>
using namespace std;
struct zawodnik {
  int l, r, t, c;
};
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<zawodnik> zaw(m);
  for (int i = 0; i < m; ++i) {
    cin >> zaw[i].l >> zaw[i].r >> zaw[i].t >> zaw[i].c;
    --zaw[i].l;
    --zaw[i].r;
  }
  vector<int> rek(n, -1);
  for (int i = 0; i < m; ++i) {
    for (int j = zaw[i].l; j <= zaw[i].r; ++j) {
      if (rek[j] == -1)
        rek[j] = i;
      else if (zaw[i].t < zaw[rek[j]].t)
        rek[j] = i;
    }
  }
  int koszt = 0;
  for (int i = 0; i < n; ++i)
    if (rek[i] != -1) koszt += zaw[rek[i]].c;
  cout << koszt;
  return 0;
}
