#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > p(m);
  vector<long long> t(m), c(m);
  for (long long i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second >> t[i] >> c[i];
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long mn = LONG_MAX, g = 0;
    for (long long j = 0; j < m; j++) {
      if (i >= p[j].first && i <= p[j].second) {
        if (t[j] < mn) {
          mn = t[j];
          g = c[j];
        }
      }
    }
    ans = ans + g;
  }
  cout << ans;
}
