import std.stdio;
import std.array;
import std.conv;
import std.algorithm;

struct gom{
	int x = -1;
	int depth=-1;
	this(int a,int b){
		x = a;
		depth = b;
	}
}

gom[][5000] kugi;

void main(){
	string[] fi = readln().split();
	int n = to!int(fi[0]);
	int m = to!int(fi[1]);

	for(int i = 0;i < m;++i){
		string[] input = readln().split();
		int a = to!int(input[0]);
		int b = to!int(input[1]);
		int c = to!int(input[2]);
		kugi[a-1] ~= gom(b-1,c);
	}

	int res = 0;
	int[] now = new int[5001];
	int[] next = new int[5001];
	now[] = -1;
	next[] = -1;
	for(int i = 0;i < n;++i){
		foreach(gom k;kugi[i]){
			now[k.x] = max(now[k.x],k.depth);
		}		
		foreach(int x,int k;now[0..i+1]){
			if(k >= 0){
				++res;
			}
			next[x] = max(next[x],k-1);
			next[x+1] = max(next[x+1],k-1);
		}

		int[] tmp = now;
		now = next;
		next = tmp;
		next[] = -1;
	}

	writeln(res);
}