#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long B[1005][2];
  long long n, m;
  cin >> n >> m;
  long long A[m][4];
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < 4; j++) {
      cin >> A[i][j];
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 0; j < 2; j++) {
      B[i][j] = 1005;
    }
  }
  for (long long i = 0; i < m; i++) {
    for (long long j = A[i][0]; j <= A[i][1]; j++) {
      long long t = A[i][2];
      if (t < B[j][0]) {
        B[j][0] = t;
        B[j][1] = A[i][3];
      }
    }
  }
  long long sum = 0;
  for (long long i = 1; i < n + 1; i++) {
    if (B[i][1] != 1005) {
      sum += B[i][1];
    }
  }
  cout << sum << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
