#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) {
  return (a.first == b.first) ? a.second > b.second : a.first < b.first;
}
struct participant {
  int l, r, t, c;
};
bool compare(participant a, participant b) {
  return (a.l == b.l) ? a.r < b.r : a.l < b.l;
}
int solve() {}
int main() {
  int n, m;
  cin >> n >> m;
  int i = 0;
  participant a[m + 1];
  while (i < m) {
    cin >> a[i].l >> a[i].r >> a[i].t >> a[i].c;
    i++;
  }
  int total = 0, id;
  for (int sec = 1; sec <= n; sec++) {
    int time = 100000;
    bool flag = false;
    for (int j = 0; j < m; j++) {
      if (sec >= a[j].l and sec <= a[j].r) {
        if (a[j].t < time) {
          id = j;
          time = a[j].t;
          flag = true;
        }
      }
    }
    if (flag) total += a[id].c;
  }
  cout << total << '\n';
}
