#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  vector<vector<int> > sp;
  scanf("%i%i", &n, &m);
  vector<int> v;
  v.resize(4, 0);
  for (int i = 0; i < m; i++) {
    int l, r, t, c;
    scanf("%i%i%i%i", &l, &r, &t, &c);
    v[0] = l;
    v[1] = r;
    v[2] = t;
    v[3] = c;
    sp.push_back(v);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int c = 0;
    int ind = -1;
    int mint = 9999999;
    int mint2 = 9999999;
    for (int j = 0; j < m; j++) {
      if (i + 1 >= sp[j][0] && i + 1 <= sp[j][1] && sp[j][2] < mint) {
        ind = j;
        c = sp[j][3];
        mint = sp[j][2];
      }
    }
    ans += c;
  }
  printf("%i\n", ans);
  return 0;
}
