#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[m][4];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 4; j++) cin >> arr[i][j];
  }
  int sec = 1, res = 0;
  while (sec <= n) {
    int min = INT_MAX, k = -1;
    for (int i = 0; i < m; i++) {
      if (sec >= arr[i][0] && sec <= arr[i][1]) {
        if (arr[i][2] < min) {
          min = arr[i][2];
          k = i;
        }
      }
    }
    if (k != -1) res = res + arr[k][3];
    sec++;
  }
  cout << res;
  return 0;
}
