#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, min = 5000;
  cin >> n >> m;
  vector<int> a[m];
  int d;
  for (int i = 0; i < m; i++) {
    cin >> d;
    a[i].push_back(d);
    cin >> d;
    a[i].push_back(d);
    cin >> d;
    a[i].push_back(d);
    cin >> d;
    a[i].push_back(d);
  }
  long long int count = 0;
  for (int k = 1; k <= n; k++) {
    min = 5000;
    d = 0;
    for (int i = 0; i < m; i++) {
      if (k >= a[i][0] && k <= a[i][1]) {
        if (a[i][2] < min) {
          min = a[i][2];
          d = a[i][3];
        }
      }
    }
    count += d;
  }
  cout << count;
}
