#include <bits/stdc++.h>
#define Maxn 307
#define modp 1000000007
using namespace std;
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m;
bool vis[Maxn][Maxn][Maxn];
int f[Maxn][Maxn][Maxn];
multiset<pair<int,int> >s[Maxn];
int dfs(int a,int b,int c)
{
	if (vis[a][b][c]) return f[a][b][c];
	vis[a][b][c]=true;
	int now=max(a,max(b,c));
	for (multiset<pair<int,int> >::iterator it=s[now].begin();it!=s[now].end();it++)
	{
		int r=0;
		r=(a>=(*it).first)+(b>=(*it).first)+(c>=(*it).first);
		if (r!=(*it).second)
		{
			f[a][b][c]=0;
			return 0;
		}
	}
	if (now>=n)
	{
		f[a][b][c]=1;
		return 1;
	}
	f[a][b][c]=(f[a][b][c]+dfs(now+1,b,c))%modp;
	f[a][b][c]=(f[a][b][c]+dfs(a,now+1,c))%modp;
	f[a][b][c]=(f[a][b][c]+dfs(a,b,now+1))%modp;
	return f[a][b][c];
}
int main()
{
	n=read(),m=read();
	for (int i=1;i<=m;i++)
	{
		int l=read(),r=read(),x=read();
		s[r].insert(make_pair(l,x));
	}
	printf("%d\n",dfs(0,0,0));
	return 0;
}
