#include <bits/stdc++.h>
using namespace std;
int l[100], r[100], t[100], c[100];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, money = 0, cur = 0, mn = (1 << 30 - 1);
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> l[i] >> r[i] >> t[i] >> c[i];
  for (int i = 1; i <= n; i++) {
    mn = (1 << 30 - 1);
    cur = 0;
    for (int j = 0; j < m; j++) {
      if (i >= l[j] && i <= r[j] && mn > t[j]) {
        mn = t[j];
        cur = c[j];
      }
    }
    money += cur;
  }
  cout << money;
  return 0;
}
