#include <bits/stdc++.h>
using namespace std;
int road[1000];
struct athe {
  int t;
  int pro;
} A[1000];
int main() {
  int block, n;
  cin >> block >> n;
  int a, b, c, d;
  for (int i = 1; i <= n; i++) {
    cin >> a >> b >> c >> d;
    A[i].t = c, A[i].pro = d;
    for (int j = a; j <= b; j++)
      if (road[j] && (A[road[j]].t > A[i].t))
        road[j] = i;
      else if (road[j] && (A[road[j]].t == A[i].t && road[j] > i))
        road[j] = i;
      else if (!road[j])
        road[j] = i;
  }
  int sum = 0;
  for (int k = 1; k <= block; k++) sum += A[road[k]].pro;
  cout << sum << endl;
  return 0;
}
