#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

inline void setin(string s) {
	freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
	freopen(s.c_str(), "w", stdout);
}

template <typename T> inline T range(T l, T r) {
	return uniform_int_distribution <T>(l, r)(rng);
}
 
template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

template <typename T> ostream &operator << (ostream &cout, vector <T> x) {
	for(auto it = x.begin(); it != x.end(); ++it) {
		if(it == x.begin())
			cout << "{" << *it;
		else
			cout << ", " << *it;
	}
	cout << "}";
	return cout;
}

template <typename T> ostream &operator << (ostream &cout, set <T> x) {
	for(auto it = x.begin(); it != x.end(); ++it) {
		if(it == x.begin())
			cout << "{" << *it;
		else
			cout << ", " << *it;
	}
	cout << "}";
	return cout;
}

const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 3e2 + 15;
int n, m;

int dp[N][N][N];

struct pt {
	int l, r, x;
} a[N];

int is[4][N][N];

inline int get(int i, int r, int l1, int l2) {
	if(l1 > l2 || l2 > r || l1 > r)
		return 0;
	return is[i][l2][r] - is[i][l1 - 1][r];
}

inline int add(int a, int b) {
	a += b;
	if(a >= mod)
		a -= mod;
	if(a < 0)
		a += mod;
	return a;
}

inline void add_t(int &a, int b) {
	a = add(a, b);
}

inline int mt(int a, int b) {
	return (ll)a * b % mod;
}

inline void precalc() {
	for(int i = 1; i <= m; ++i)
		++is[a[i].x][a[i].l][a[i].r];
	for(int i = 1; i <= 3; ++i)
		for(int r = 1; r <= n; ++r)
			for(int l = 1; l <= r; ++l)
				is[i][l][r] += is[i][l-1][r];
}

main() {
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	// setin("input.txt");
	cin >> n >> m;
	for(int i = 1; i <= m; ++i)
		cin >> a[i].l >> a[i].r >> a[i].x;
	precalc();
	dp[0][0][0] = 1;
	for(int a = 0; a <= n; ++a) {
		for(int b = 0; b <= n; ++b) {
			for(int c = 0; c <= n; ++c) {
				vector <int> cur = {a, b, c};
				sort(cur.begin(), cur.end());
				if(get(1, cur[2], cur[0] + 1, cur[1]) || get(3, cur[2], cur[0] + 1, cur[1]))
					dp[a][b][c] = 0;
				if(get(2, cur[2], cur[1] + 1, cur[2]) || get(3, cur[2], cur[1] + 1, cur[2]))
					dp[a][b][c] = 0;
				if(get(1, cur[2], 1, cur[0]) || get(2, cur[2], 1, cur[0]))
					dp[a][b][c] = 0;
				int k = max({a, b, c});
				add_t(dp[k+1][b][c], dp[a][b][c]);
				add_t(dp[a][k+1][c], dp[a][b][c]);
				add_t(dp[a][b][k+1], dp[a][b][c]);
			}
		}
	}
	int ans = 0;
	for(int i = 0; i <= n; ++i) {
		for(int j = 0; j <= n; ++j) {
			add_t(ans, dp[n][i][j]);
			add_t(ans, dp[i][n][j]);
			add_t(ans, dp[i][j][n]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 118784