#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> start(m);
  vector<int> ending(m);
  vector<int> time(m);
  vector<int> prize(m);
  int money = 0;
  for (int i = 0; i < m; i++) {
    cin >> start[i] >> ending[i] >> time[i] >> prize[i];
  }
  int mn = 9000;
  int currprize;
  for (int j = 1; j <= n; j++) {
    mn = 9000;
    currprize = 0;
    for (int i = 0; i < m; i++) {
      if (start[i] <= j && ending[i] >= j && time[i] < mn) {
        mn = time[i];
        currprize = prize[i];
      }
    }
    money += currprize;
  }
  cout << money << endl;
}
