#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1E-9;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double PI = 2 * acos(.0);
int track[1005][1005];
int main() {
  memset(track, 0, sizeof(track));
  int n, m, li, ri, ti, ci;
  cin >> n >> m;
  int mini = INF;
  int cost = 0;
  vector<int> cost_part;
  for (int i = 0; i < (int)(m); i++) {
    cin >> li >> ri >> ti >> ci;
    for (int j = li; j < (int)(ri + 1); j++) {
      track[i][j] = ti;
    }
    cost_part.push_back(ci);
  }
  int sum_cost = 0;
  for (int i = 1; i < (int)(n + 1); i++) {
    mini = INF;
    cost = 0;
    for (int j = 0; j < (int)(m); j++) {
      if (track[j][i] == 0) continue;
      if (mini > track[j][i]) {
        mini = track[j][i];
        cost = cost_part[j];
      }
    }
    if (mini == INF) continue;
    sum_cost += cost;
  }
  cout << sum_cost << endl;
  return 0;
}
