#include <bits/stdc++.h>
using namespace std;
int n, m, l[107], r[107], t[107], c[107];
long long int sum;
void read_input() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> t[i] >> c[i];
  }
}
void debug(int highest_profit) {
  for (int i = 0; i < m; i++) {
    if (c[i] == highest_profit) {
      cout << i << '\n';
    }
  }
}
int natural(long long int n) {
  if (n <= 0) {
    return 0;
  } else {
    return n;
  }
}
void solve() {
  read_input();
  for (int i = 1; i <= n; i++) {
    long long int winner_time = 1e9, highest_profit = 0;
    for (int j = 0; j < m; j++) {
      if (l[j] <= i && r[j] >= i && t[j] < winner_time) {
        winner_time = t[j];
        highest_profit = c[j];
      }
    }
    sum += highest_profit;
  }
  cout << sum << '\n';
}
int main() { solve(); }
