#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > v[n + 1];
  int c[m];
  for (int i = 0; i < (int)m; ++i) {
    int l, r, t;
    cin >> l >> r >> t >> c[i];
    for (int j = l; j <= r; ++j) {
      v[j].push_back(pair<int, int>(t, i));
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)n + 1; ++i) {
    if (v[i].size()) {
      ans += c[min_element((v[i]).begin(), (v[i]).end())->second];
    }
  }
  cout << ans << endl;
}
