#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool checkprime(long long n) {
  long long i = 2;
  while (i * i <= n) {
    if (n % i == 0) return 0;
    i++;
  }
  return 1;
}
long long fact(long long n) {
  if (n == 0) return 1;
  return n * fact(n - 1);
}
bool compare(const pair<long long, long long>& i,
             const pair<long long, long long>& j) {
  return i.first < j.first;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long ans = 0;
  long long l[m + 1], r[m + 1], t[m + 1], c[m + 1];
  for (long long i = 1; i <= m; i++) cin >> l[i] >> r[i] >> t[i] >> c[i];
  for (long long i = 1; i <= n; i++) {
    long long mxc = 0, mx = 100000, mxi = -1;
    for (long long j = 1; j <= m; j++) {
      if (i >= l[j] && i <= r[j] && t[j] < mx) {
        mxi = j;
        mx = t[j];
        mxc = c[j];
      }
    }
    ans += mxc;
  }
  cout << ans << '\n';
  return 0;
}
