#include <bits/stdc++.h>
using namespace std;
long double const PI = acosl(-1);
const int INF = 1E9 + 4;
const int MAXN = 1e5 + 123;
const long double EPS = 1e-18;
const long long MOD = 1e9 + 7;
long long luc[123][123];
void solve() {
  int n, m;
  cin >> n >> m;
  int l[m], r[m], t[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> t[i] >> c[i];
    for (int j = l[i]; j <= r[i]; j++) luc[i][j] = t[i];
  }
  long long ans = 0;
  for (int j = 1; j <= n; j++) {
    int mn = INF;
    for (int i = 0; i < m; i++)
      if (luc[i][j] < mn && luc[i][j] != 0) mn = luc[i][j];
    int mx = 0;
    for (int i = 0; i < m; i++) {
      if (luc[i][j] == mn) {
        mx = c[i];
        break;
      }
    }
    ans += mx;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) solve();
  return 0;
}
