#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<int,int>;
const int MOD = 1e9+7;
int n, m, l, r, x;
long long dp[305][305] = {1}, ans;
vector<P> p[305];
int main(){
	cin >> n >> m;
	rep(i,m){
		cin >> l >> r >> x;
		p[r-1].push_back(P(l,x));
	}
	rep(i,n){
		rep(j,i) rep(k,i) (dp[i][j] += dp[max(j,k)][min(j,k)]) %= MOD;
		for(P t: p[i]){
			tie(l,x) = t;
			rep(j,i+1) rep(k,j+1) if(x+(j<l)+(k<l)-3) dp[j][k] = 0;
		}
	}
	rep(i,n) rep(j,i) (ans += 6*dp[i][j]) %= MOD;
	cout << (ans + dp[0][0]*3) % MOD;
}