#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>> v;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    vector<int> sv;
    for (int j = 0; j < 4; j++) {
      int k;
      cin >> k;
      sv.push_back(k);
    }
    v.push_back(sv);
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    int min_t = -1;
    for (int j = 0; j < v.size(); j++) {
      if (v[j][0] <= i && v[j][1] >= i) {
        if (min_t == -1) min_t = j;
        min_t = (v[min_t][2] > v[j][2] ? j : min_t);
      }
    }
    if (min_t > -1) sum += v[min_t][3];
  }
  cout << sum << endl;
  return 0;
}
