//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n, m;
int l[400], r[400], a[400], can[400][400][3];
ll dp[310][310][310];

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

	scanf("%d%d", &n, &m);
	
	for (int i=0; i<m; i++) {
		scanf("%d%d%d", &l[i], &r[i], &a[i]);
	}
	
	for (int i=0; i<=n; i++) {
		for (int j=i; j<=n; j++) {
			for (int k=1; k<=3; k++) {
				can[i][j][k] = 1;
			}
			if (i == j && i) can[i][j][2] = 0, can[i][j][3] = 0;
		}
	}
	
	for (int i=0; i<m; i++) {
		for (int j=1; j<=3; j++) if (j != a[i]) {
			can[l[i]][r[i]][j] = 0;
		}
		for (int j=l[i]; j<=r[i]; j++) {
			for (int k=j; k<=r[i]; k++) {
				for (int t=1; t<=3; t++) if (t > a[i]) {
					can[j][k][t] = 0;
				}
			}
		}
		for (int j=l[i]; j>=0; j--) {
			for (int k=r[i]; k<=n; k++) {
				for (int t=1; t<=3; t++) if (t < a[i]) {
					can[j][k][t] = 0;
				}
			}
		}
	}
	
	ll ans = 0;
	dp[1][0][0] = 1;
	dp[0][0][1] = 1;
	dp[0][1][0] = 1;
//	cout << can[3][4][2] << endl;
	for (int i=1; i<=n; i++) {
		for (int j=0; j<=i; j++) {
			for (int k=0; k<=j; k++) {
				if (!k && !j && !can[1][i][1]) {
					dp[i][j][k] = 0;
					dp[i][j][k] = 0;
					dp[i][k][j] = 0;
					dp[j][i][k] = 0;
					dp[j][k][i] = 0;
					dp[k][i][j] = 0;
					dp[k][j][i] = 0;
					continue;
				}
				if (!k && j && (!can[1][i][2] || !can[j][i][2] || !can[j + 1][i][1])) {
					dp[i][j][k] = 0;
					dp[i][k][j] = 0;
					dp[j][i][k] = 0;
					dp[j][k][i] = 0;
					dp[k][i][j] = 0;
					dp[k][j][i] = 0;
					continue;
				}
				if (k && j && (!can[k][i][3] || !can[j + 1][i][1] || !can[k + 1][i][2]) || !can[j][i][2]) {
//					cout << i << " " << j << " " << k << endl;
					dp[i][j][k] = 0;
					dp[i][k][j] = 0;
					dp[j][i][k] = 0;
					dp[j][k][i] = 0;
					dp[k][i][j] = 0;
					dp[k][j][i] = 0;
					continue;
				}
//				cout << i << " " << j << " " << k << " "<< dp[i][j][k] << " " << dp[i][k][j] << " " << dp[j][k][i] << " " << dp[j][i][k] << " " << dp[k][i][j] << " " << dp[k][j][i] << endl;
				if (j == 0 && k == 0) {
					(dp[i + 1][j][k] += dp[i][j][k]) %= MOD;
					(dp[i][i + 1][k] += dp[i][j][k]) %= MOD;
					(dp[i][j][i + 1] += dp[i][j][k]) %= MOD;
					(dp[i + 1][i][k] += dp[j][i][k]) %= MOD;
					(dp[j][i + 1][k] += dp[j][i][k]) %= MOD;
					(dp[j][i][i + 1] += dp[j][i][k]) %= MOD;
					(dp[i + 1][k][i] += dp[j][k][i]) %= MOD;
					(dp[j][i + 1][i] += dp[j][k][i]) %= MOD;
					(dp[j][k][i + 1] += dp[j][k][i]) %= MOD;
					if (n == i) {
						ans += dp[i][j][k] + dp[k][i][j] + dp[k][j][i];
					}
					continue;
				}
				if (i != n) {
//					if (i == 2 && j == 1 && k == 0) cout << dp[3][2][1] << endl;
					(dp[i + 1][j][k] += dp[i][j][k]) %= MOD;
					(dp[i][i + 1][k] += dp[i][j][k]) %= MOD;
					(dp[i][j][i + 1] += dp[i][j][k]) %= MOD;
					(dp[i + 1][k][j] += dp[i][k][j]) %= MOD;
					(dp[i][i + 1][j] += dp[i][k][j]) %= MOD;
					(dp[i][k][i + 1] += dp[i][k][j]) %= MOD;
					(dp[i + 1][i][k] += dp[j][i][k]) %= MOD;
					(dp[j][i + 1][k] += dp[j][i][k]) %= MOD;
					(dp[j][i][i + 1] += dp[j][i][k]) %= MOD;
					(dp[i + 1][k][i] += dp[j][k][i]) %= MOD;
					(dp[j][i + 1][i] += dp[j][k][i]) %= MOD;
					(dp[j][k][i + 1] += dp[j][k][i]) %= MOD;
					(dp[i + 1][i][j] += dp[k][i][j]) %= MOD;
//					if (i == 2 && j == 1 && k == 0) cout << dp[0][2][1] << endl;
					(dp[k][i + 1][j] += dp[k][i][j]) %= MOD;
					(dp[k][i][i + 1] += dp[k][i][j]) %= MOD;
					(dp[i + 1][j][i] += dp[k][j][i]) %= MOD;
					(dp[k][i + 1][i] += dp[k][j][i]) %= MOD;
					(dp[k][j][i + 1] += dp[k][j][i]) %= MOD;
				}
				else {
					(ans += dp[i][j][k] + dp[i][k][j] + dp[j][k][i] + dp[j][i][k]  + dp[k][i][j] + dp[k][j][i]) %= MOD;
				}
			}
		}
	}
	
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 230272