#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = ({
    int x;
    scanf("%d", &x);
    x;
  }),
      m = ({
        int x;
        scanf("%d", &x);
        x;
      });
  int time[500], prof[500];
  for (int i = 0; i < 500; i++) {
    time[i] = 100000;
  }
  for (int i = 1; i <= m; i++) {
    int l = ({
      int x;
      scanf("%d", &x);
      x;
    }),
        r = ({
          int x;
          scanf("%d", &x);
          x;
        }),
        t = ({
          int x;
          scanf("%d", &x);
          x;
        }),
        c = ({
          int x;
          scanf("%d", &x);
          x;
        });
    for (int j = l; j <= r; j++) {
      if (t < time[j]) {
        time[j] = t;
        prof[j] = c;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (time[i] == 100000) continue;
    ans += prof[i];
  }
  printf("%d\n", ans);
}
