#include <bits/stdc++.h>
using namespace std;
int big(int a, int b) { return a > b ? a : b; }
struct node {
  int t, cost;
};
int main() {
  int n = ({
    int t;
    scanf("%d", &t);
    t;
  }),
      m = ({
        int t;
        scanf("%d", &t);
        t;
      });
  node v[102];
  for (int i = 0; i < 102; i++) {
    v[i + 1].t = 1 << 25;
    v[i + 1].cost = 1 << 25;
  }
  for (int i = 0; i < m; i++) {
    int sx = ({
      int t;
      scanf("%d", &t);
      t;
    }),
        sy = ({
          int t;
          scanf("%d", &t);
          t;
        }),
        ti = ({
          int t;
          scanf("%d", &t);
          t;
        }),
        co = ({
          int t;
          scanf("%d", &t);
          t;
        });
    for (int j = sx; j <= sy; j++) {
      if (ti < v[j].t) {
        v[j].t = ti;
        v[j].cost = co;
      }
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i].cost < 1003) res += v[i].cost;
  }
  cout << res;
  return 0;
}
