#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  long long n, m, p, q, r, s, ans = 0, u;
  cin >> n >> m;
  vector<long long> a[m];
  for (long long i = 0; i < m; i++) {
    cin >> p >> q >> r >> s;
    a[i].push_back(p);
    a[i].push_back(q);
    a[i].push_back(r);
    a[i].push_back(s);
  }
  for (long long i = 1; i < n + 1; i++) {
    s = 0;
    long long t = INT_MAX;
    for (long long j = 0; j < m; j++) {
      if (a[j][0] <= i && a[j][1] >= i) {
        if (a[j][2] < t) {
          t = a[j][2];
          s = a[j][3];
        }
      }
    }
    ans += s;
  }
  cout << ans;
}
