#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
int n, m;
pair<pair<int, int>, int> a[200];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) a[i].first.first = inf;
  for (int i = 0; i < m; ++i) {
    int l, r, t, c;
    scanf("%d %d %d %d", &l, &r, &t, &c);
    pair<pair<int, int>, int> tek;
    tek.first.first = t;
    tek.first.second = i + 1;
    tek.second = c;
    for (int j = l; j <= r; ++j) a[j] = min(a[j], tek);
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) ans += a[i].second;
  cout << ans << endl;
  return 0;
}
