#include <bits/stdc++.h>
using namespace std;
priority_queue<tuple<int, int, int, int, int> > maxq;
vector<tuple<int, int, int, int, int> > evs;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r, t, c;
    cin >> l >> r >> t >> c;
    evs.push_back({l, r, i, t, c});
  }
  sort(evs.begin(), evs.end());
  int curr = 0;
  int total = 0;
  for (int i = 1; i <= n; i++) {
    while (curr < m && get<0>(evs[curr]) <= i) {
      int ind, l, r, t, c;
      tie(l, r, ind, t, c) = evs[curr++];
      maxq.push({-t, -ind, l, r, c});
    }
    int t, ind, l, r = -1, c;
    if (maxq.empty()) continue;
    tie(t, ind, l, r, c) = maxq.top();
    while (r < i) {
      if (maxq.empty()) break;
      maxq.pop();
      tie(t, ind, l, r, c) = maxq.top();
    }
    if (maxq.empty()) continue;
    total += c;
  }
  cout << total << endl;
}
