#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int t[N];
int pos[N];
int c[N];
int n, m, l, r, tt, cc;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  int ans = 0;
  for (int i = 0; i < N; i++) t[i] = 10005, pos[i] = 10005;
  for (int i = 1; i <= m; i++) {
    cin >> l >> r >> tt >> cc;
    for (int j = l; j <= r; j++) {
      if (t[j] > tt) t[j] = tt, pos[j] = i, c[j] = cc;
      if (t[j] == tt && i < pos[j]) pos[j] = i, c[j] = cc;
    }
  }
  for (int i = 1; i <= n; i++) ans += c[i];
  cout << ans << endl;
}
