#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> l(m);
  vector<int> r(m);
  vector<int> t(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> t[i] >> c[i];
  }
  int maxC = 0;
  int timeMax = 1001;
  int answ = 0;
  for (int i = 0; i < n; i++) {
    maxC = 0;
    timeMax = 1001;
    for (int j = 0; j < m; j++) {
      if (l[j] <= (i + 1) && (i + 1) <= r[j]) {
        if (timeMax > t[j]) {
          timeMax = t[j];
          maxC = c[j];
        }
      }
    }
    answ += maxC;
  }
  cout << answ << endl;
  return 0;
}
