#include <bits/stdc++.h>
using namespace std;
const int maxn = 110, inf = 10000000;
int arr[2][maxn];
int main() {
  fill(arr[0], arr[0] + maxn, inf);
  int n, m, l, r, t, c;
  cin >> n >> m;
  while (m--) {
    cin >> l >> r >> t >> c;
    l--;
    r--;
    for (int i = l; i <= r; i++)
      if (t < arr[0][i]) {
        arr[0][i] = t;
        arr[1][i] = c;
      }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) ans += arr[1][i];
  cout << ans << endl;
}
