#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> costs;
  vector<int> wintimes(n, INT_MAX);
  vector<int> winners(n, -1);
  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 (t < wintimes[j]) {
        winners[j] = i;
        wintimes[j] = t;
      }
    }
    costs.push_back(c);
  }
  int total = 0;
  for (int i = 0; i < n; i++) {
    if (winners[i] != -1) {
      total += costs[winners[i]];
    }
  }
  cout << total << endl;
  return 0;
}
