#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> cc[105];
  for (int i = 1; i <= m; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int j = a; j <= b; j++) {
      if (!cc[j].first || c < cc[j].first) {
        cc[j].first = c;
        cc[j].second = d;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += cc[i].second;
  cout << ans;
}
