#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> mp;
  map<int, int> ans;
  int n, m, i, j, k, a, b, c, d, s = 0;
  for (i = 1; i < 110; i++) mp[i] = INT_MAX;
  cin >> n >> m;
  for (j = 0; j < m; j++) {
    cin >> a >> b >> c >> d;
    for (i = a; i <= b; i++) {
      if (c < mp[i]) {
        mp[i] = c;
        ans[i] = d;
      }
    }
  }
  for (i = 1; i <= n; i++) s += ans[i];
  cout << s << endl;
  return 0;
}
