#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  int L[101], R[101], T[101], P[101];
  for (int i = 0; i < m; i++) cin >> L[i] >> R[i] >> T[i] >> P[i];
  int ats = 0;
  for (int i = 1; i <= n; i++) {
    int cur = 0;
    int tm = INT_MAX;
    for (int j = 0; j < m; j++)
      if (L[j] <= i && R[j] >= i && T[j] < tm) cur = P[j], tm = T[j];
    ats += cur;
  }
  cout << ats;
  return 0;
}
