#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

int dp[310][310][310];
vector<int> cond[310];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> l(m), r(m), x(m);
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> r[i] >> x[i];
		cond[r[i]].push_back(i);
	}
	dp[0][0][0] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (j != 0 && j == i) continue;
			for (int k = 0; k <= n; k++) {
				if (k != 0 && (k == i || k == j)) continue;
				int cmax = max({i, j, k});
				for (int idx : cond[cmax]) {
					int cnt = 0;
					cnt += (l[idx] <= i);
					cnt += (l[idx] <= j);
					cnt += (l[idx] <= k);
					if (cnt != x[idx]) dp[i][j][k] = 0;
				}
				(dp[cmax + 1][j][k] += dp[i][j][k]) %= MOD;
				(dp[i][cmax + 1][k] += dp[i][j][k]) %= MOD;
				(dp[i][j][cmax + 1] += dp[i][j][k]) %= MOD;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != 0 && i == j) continue;
			(ans += dp[n][i][j]) %= MOD;
			(ans += dp[i][n][j]) %= MOD;
			(ans += dp[i][j][n]) %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}