#include <bits/stdc++.h>
using namespace std;
const long long int INF = 9223372036854775807LL;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroint-loops")
long long int power(long long int b, long long int e, long long int m) {
  if (b == 0) return 0;
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
long long int power(long long int b, long long int e) {
  if (b == 0) return 0;
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
bool isPowerOfTwo(long long int x) { return (x && !(x & (x - 1))); }
bool comp(pair<long long int, pair<long long int, long long int>> p1,
          pair<long long int, pair<long long int, long long int>> p2) {
  if (p1.first < p2.first) return true;
  if (p1.first == p2.first) {
    if (p1.second.second < p2.second.second)
      return true;
    else
      return false;
  }
  return false;
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  vector<pair<long long int, pair<long long int, long long int>>> v[n + 1];
  for (long long int i = 0; i < m; i++) {
    long long int a, b, t, c;
    cin >> a >> b >> t >> c;
    for (long long int j = a; j <= b; j++) v[j].push_back({t, {c, i}});
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    if (v[i].size()) {
      sort((v[i]).begin(), (v[i]).end(), comp);
      ans += v[i][0].second.first;
    }
  }
  cout << ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int tt = 1;
  while (tt--) {
    solve();
    cout << "\n";
  }
  return 0;
}
