#include <bits/stdc++.h>
using namespace std;
struct contestent {
  int ind;
  int start;
  int end;
  int time;
  int profit;
  bool operator<(contestent c) const {
    if (time < c.time) return true;
    if (time == c.time && ind < c.ind) return true;
    return false;
  }
};
int main() {
  int n, m;
  cin >> m >> n;
  int i, j;
  vector<contestent> cc;
  for (i = 0; i < n; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    contestent con;
    con.ind = i;
    con.start = a;
    con.end = b;
    con.time = c;
    con.profit = d;
    cc.push_back(con);
  }
  sort(cc.begin(), cc.end());
  int p = 0;
  for (i = 1; i <= m; i++) {
    int t = 0;
    for (j = 0; j < n; j++) {
      if (cc[j].start <= i && cc[j].end >= i) {
        t = cc[j].profit;
        break;
      }
    }
    p += t;
  }
  cout << p << "\n";
  return 0;
}
