#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e6 + 3;
const int INFI = 1e9 * 2;
const long long LINFI = 1e17;
const double pi = acos(-1.0);
const int N = 111;
const int M = 222222;
const int move[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1};
int a[N], b[N];
int main() {
  int n, m, l, r, t, c, ans;
  while (scanf("%d%d", &n, &m) != EOF) {
    ans = 0;
    memset(a, -1, sizeof(a));
    memset(b, 0, sizeof(b));
    for (int i = 0; i < m; i++) {
      scanf("%d%d%d%d", &l, &r, &t, &c);
      for (int j = l; j <= r; j++)
        if (a[j] > t || a[j] == -1) a[j] = t, b[j] = c;
    }
    for (int i = 1; i <= n; i++)
      if (a[i] > 0) ans += b[i];
    printf("%d\n", ans);
  }
  return 0;
}
