#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<long long, long long> mp;
  vector<vector<long long>> start(n), end(n);
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    long long c;
    cin >> c;
    start[l].push_back(c);
    end[r].push_back(c);
  }
  vector<long long> d(n, -1);
  for (int i = 0; i < n; i++) {
    if (!start[i].empty()) {
      for (auto e : start[i]) {
        mp[e]++;
      }
    }
    d[i] = (*mp.begin()).first;
    if (!end[i].empty()) {
      for (auto e : end[i]) {
        mp[e]--;
        if (mp[e] == 0) {
          mp.erase(e);
        }
      }
    }
  }
  d[0] = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    while (i < n - 1 && d[i] == d[i + 1]) {
      i++;
    }
    ans += d[i];
  }
  cout << ans << endl;
}
