#include <bits/stdc++.h>
using namespace std;

const int mo=int(1e9+7);
struct node{int l,r,x,n;}a[305];
int n,m,f[305][305][305],h[305],ans;

bool check(int i,int j,int k)
{
	for (int x=h[i]; x; x=a[x].n)
		{
			if ((a[x].x==1)&&(a[x].l<=j))  return 0;
			if ((a[x].x==2)&&((a[x].l>j)||(a[x].l<=k)))  return 0;
			if ((a[x].x==3)&&(a[x].l>k))  return 0;
		}
	return 1;
}

void work()
{
	scanf("%d %d",&n,&m);
	for (int i=1; i<=m; i++)
		scanf("%d %d %d",&a[i].l,&a[i].r,&a[i].x),a[i].n=h[a[i].r],h[a[i].r]=i;
	f[0][0][0]=1;
	for (int i=0; i<n; i++)
		for (int j=0; j<=i; j++)
			for (int k=0; k<=j; k++)
				if ((f[i][j][k])&&(check(i,j,k)))
					{
						f[i+1][j][k]=(f[i+1][j][k]+f[i][j][k])%mo;
						f[i+1][i][k]=(f[i+1][i][k]+f[i][j][k])%mo;
						f[i+1][i][j]=(f[i+1][i][j]+f[i][j][k])%mo;
					}
	for (int j=0; j<=n; j++)
		for (int k=0; k<=j; k++)
			if (check(n,j,k))
				ans=(ans+f[n][j][k])%mo;
	printf("%d",ans);
}

int main()
{
	work();
	return 0;
}
