#include <bits/stdc++.h>

using namespace std;

#define REP(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";

template <typename T>
using V = vector<T>;

typedef long double ld;


int N, M;
vector<vector<pair<int, int>>> conds;

const int64_t MOD = 1e9+7;

V<V<V<int>>> DP(305, V<V<int>>(305, V<int>(305, -1)));

int ways(int r, int b, int g) {
	if (DP[r][b][g] != -1)
		return DP[r][b][g];
	int i = max(r, g);
	i = max(i, b);
	++i;
	bool ok = 1;
	for (auto& cond : conds[i-1]) {
		int l, c;
		tie(l, c) = cond;
		int cc = 0;
		if (r >= l)
			++cc;
		if (b >= l)
			++cc;
		if (g >= l)
			++cc;
		if (c != cc) {
			ok = 0;
			break;
		}
	}
	if (!ok)
		return DP[r][b][g] = 0;
	if (i == N+1)
		return DP[r][b][g] = 1;
	int64_t ans = ways(i, b, g);
	ans %= MOD;
	ans += ways(r, i, g);
	ans %= MOD;
	ans += ways(r, b, i);
	ans %= MOD;
	return DP[r][b][g] = ans;

}


int main() {
	cin >> N >> M;
	conds.resize(N+1);
	REP(i, M) {
		int l, r, x;
		cin >> l >> r >> x;
		conds[r].emplace_back(l, x);
	}

	cout << ways(0, 0, 0) << endl;
}