#include <bits/stdc++.h>
using namespace std;
long long int Mod = 1000000007;
int main() {
  int i, j, k, l, m, n, x, y, z, r, t, c;
  cin >> n >> m;
  n++;
  m++;
  int a[110][110], b[110];
  for (i = 0; i < 110; i++) {
    for (j = 0; j < 110; j++) a[i][j] = -1;
  }
  for (i = 1; i < m; i++) {
    cin >> l >> r >> t >> c;
    for (j = l; j <= r; j++) {
      a[i][j] = t;
    }
    b[i] = c;
  }
  int s = 0;
  for (j = 1; j < 103; j++) {
    int mi = 1010, im = -5;
    for (i = m; i > 0; i--) {
      if (a[i][j] > 0 && a[i][j] <= mi) {
        mi = a[i][j];
        im = i;
      }
    }
    if (im != -5) {
      s += b[im];
    }
  }
  cout << s << endl;
  return 0;
}
