#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int p = 17;
const int inf = 1e9 + 1;
int n, m, l[200], r[200], t[200], c[200], ans = 0;
pair<int, int> uc[200];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> l[i] >> r[i] >> t[i] >> c[i];
  for (int i = 1; i <= n; i++) uc[i] = make_pair(inf, 0);
  for (int i = 1; i <= m; i++)
    for (int j = l[i]; j <= r[i]; j++)
      if (uc[j].first > t[i]) uc[j] = make_pair(t[i], c[i]);
  for (int i = 1; i <= n; i++) ans += uc[i].second;
  cout << ans;
  return 0;
}
