#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<vector>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
inline int read() {
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=310;
const int mod=1000000007;
int n,m,f[maxn][maxn][maxn];
vector<pii> G[maxn];
int check(int i,int j,int k) {
	int p=max(i,max(j,k));
	rep(z,0,G[p].size()-1) if((i>=G[p][z].xx)+(j>=G[p][z].xx)+(k>=G[p][z].xx)!=G[p][z].yy) return 0;
	return 1;
}
int main() {
	n=read();m=read();
	rep(i,1,m) {
		int l=read(),r=read(),v=read();
		G[r].pb(mp(l,v));
	}
	f[0][0][0]=1;
	int ans=0;
	rep(i,0,n) rep(j,0,n) rep(k,0,n) if(check(i,j,k)) {
		int p=max(i,max(j,k));
		if(p==n) (ans+=f[i][j][k])%=mod;
		(f[p+1][j][k]+=f[i][j][k])%=mod;
		(f[i][p+1][k]+=f[i][j][k])%=mod;
		(f[i][j][p+1]+=f[i][j][k])%=mod;
	}
	printf("%d\n",ans);
	return 0;
}
