#include<bits/stdc++.h>
using namespace std;
#define maxn 305
#define mod 1000000007
int n,m;
int rec[maxn][maxn][maxn];
int mem[maxn][maxn][maxn];
vector<pair<int,int> > q[maxn];
bool check(int a,int b,int c)
{
    int i,x = max(a,max(b,c)),now;
    if(rec[a][b][c]==-1) {
        rec[a][b][c] = 1;
        for(i=0;i<q[x].size();i++)
        {
            now = (q[x][i].first<=a) + (q[x][i].first<=b) + (q[x][i].first<=c);
            if(q[x][i].second!=now) rec[a][b][c] = 0;
        }
    }
    return rec[a][b][c];
}
int f(int a,int b,int c)
{
    int x = max(a,max(b,c)) + 1;
    if(x==n+1) return check(a,b,c);
    if(mem[a][b][c]==-1) {
        if(!check(a,b,c)) mem[a][b][c] = 0;
        else mem[a][b][c] = (f(x,b,c) + (f(a,x,c) + f(a,b,x))%mod)%mod;
    }
    return mem[a][b][c];
}
int main()
{
    int i,x,y,val;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;i++)
    {
        scanf("%d%d%d",&x,&y,&val);
        q[y].push_back({x,val});
    }
    memset(rec,-1,sizeof(rec));
    memset(mem,-1,sizeof(mem));
    printf("%d",f(0,0,0));
}
