#include <iostream>
#include <vector>
#include <set>

using namespace std;

typedef pair<int,int> P;

int main() {
    int N,M;
    cin >> N >> M;

    vector<set<P> > kugi(N+1);

    for(int i=0; i<=N; ++i) {
        kugi[i].insert(P(0,i+1)); // [0,i+1)
    }

    int ans=0;
    for(int i=0; i<M; ++i) {
        int A,B,X;
        cin >> A >> B >> X;

        for(int j=0; j<=X; ++j) {
            int l=B-1, r=B+j; // [B-1,B+j) is rubber band area
            set<P>::iterator itr=kugi[A+j-1].begin();
            while(!kugi[A+j-1].empty() && itr!=kugi[A+j-1].end()) {
                if(r <= itr->first) break;
                if(itr->second <= l) {
                    ++itr;
                    continue;
                }
                if(l<=itr->first && itr->second<=r) {
                    ans+=itr->second-itr->first;
                    itr=kugi[A+j-1].erase(itr);
                    if(kugi[A+j-1].empty()) {
                        break;
                    }
                } else if(itr->first>=l && itr->second>r) {
                    int temp=itr->second;
                    ans+=r-itr->first;
                    kugi[A+j-1].erase(itr);
                    kugi[A+j-1].insert(P(r,temp));
                    break;
                } else if(itr->first<l && itr->second<=r) {
                    int temp=itr->first;
                    ans+=itr->second-l;
                    itr=kugi[A+j-1].erase(itr);
                    kugi[A+j-1].insert(P(temp,l));
                } else if(itr->first<l && itr->second>r) {
                    int templ=itr->first, tempr=itr->second;
                    ans+=r-l;
                    kugi[A+j-1].erase(itr);
                    kugi[A+j-1].insert(P(templ,l));
                    kugi[A+j-1].insert(P(r,tempr));
                    break;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}
