#include <bits/stdc++.h>
using namespace std;
int cost[101], mx[101];
int main() {
  for (int i = 0; i <= 100; i++) mx[i] = 1e9;
  int n, m;
  cin >> m >> n;
  for (int i = 0; i < n; i++) {
    int l, r, t, c;
    cin >> l >> r >> t >> c;
    for (int j = l; j <= r; j++) {
      if (mx[j] > t) {
        mx[j] = t;
        cost[j] = c;
      }
    }
  }
  int sum = 0;
  for (int i = 1; i <= m; i++) sum += cost[i];
  cout << sum;
  return 0;
}
