#include <bits/stdc++.h>
using namespace std;
int N, M, C[110], result;
pair<int, int> section[110];
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) section[i] = make_pair(1001, 0);
  for (int i = 0; i < M; i++) {
    int l, r, t;
    cin >> l >> r >> t >> C[i];
    for (int j = l; j <= r; j++) section[j] = min(section[j], make_pair(t, i));
  }
  for (int i = 1; i <= N; i++)
    if (section[i] != make_pair(1001, 0)) result += C[section[i].second];
  cout << result << endl;
  return 0;
}
