#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void s() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  s();
  long long n, m;
  cin >> n >> m;
  long long l[m], r[m], t[m], c[m];
  for (long long i = 0; i < m; i++) cin >> l[i] >> r[i] >> t[i] >> c[i];
  long long profit = 0;
  long long sel = 0;
  while (sel++ < n) {
    long long time = INT_MAX;
    long long tempprofit = 0;
    for (long long i = 0; i < m; i++) {
      if (sel >= l[i] && sel <= r[i]) {
        if (t[i] < time) {
          time = t[i];
          tempprofit = c[i];
        }
      }
    }
    profit += tempprofit;
  }
  cout << profit << "\n";
  return 0;
}
