#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long intl;
struct query{
    int ini,fin,X;
    void Leer()
    {
        scanf("%d %d %d",&ini,&fin,&X);
    }
};
bool Cumple(query q, int r, int g, int b)
{
    int x = 0;
    if(q.ini<=r && r<=q.fin)
        x++;
    if(q.ini<=b && b<=q.fin)
        x++;
    if(q.ini<=g && g<=q.fin)
        x++;
    return x == q.X;
}
intl MOD = 1e9 + 7;
intl DP[320][320][320]; /// r g b
vector<query> Q[320];
int main()
{
    memset(DP,0,sizeof(DP));
    int N,M;
    cin>>N>>M;
    for(int i = 0;i<M;i++)
    {
        query q;
        q.Leer();
        Q[q.fin].push_back(q);
    }
    DP[1][0][0] = 1;
    DP[0][1][0] = 1;
    DP[0][0][1] = 1;

    intl R = 0;
    for(int i = 1;i<=N;i++)
    {
        for(int g = 0;g<i;g++)
            for(int b = 0;b<i;b++)
            {
                if(b!=g || b == 0 || g == 0)
                {
                    for(auto q : Q[i])
                        if(!Cumple(q,i,g,b))
                            DP[i][g][b] = 0;
 //                   cout<<i<<" - "<<g<<" - "<<g<<" : "<<DP[i][g][b]<<endl;
                    DP[i+1][g][b] = (DP[i+1][g][b] + DP[i][g][b])%MOD;
                    DP[i][i+1][b] = (DP[i][i+1][b] + DP[i][g][b])%MOD;
                    DP[i][g][i+1] = (DP[i][g][i+1] + DP[i][g][b])%MOD;
                    if(i == N)
                        R = (R+DP[i][g][b])%MOD;
                }
            }

        for(int r = 0;r<i;r++)
            for(int b = 0;b<i;b++)
            {
                if(b!=r || r == 0 || b == 0)
                {
                    for(auto q : Q[i])
                        if(!Cumple(q,r,i,b))
                            DP[r][i][b] = 0;
                    DP[i+1][i][b] = (DP[i+1][i][b] + DP[r][i][b])%MOD;
                    DP[r][i+1][b] = (DP[r][i+1][b] + DP[r][i][b])%MOD;
                    DP[r][i][i+1] = (DP[r][i][i+1] + DP[r][i][b])%MOD;
                    if(i == N)
                        R = (R+DP[r][i][b])%MOD;

                }
            }

        for(int r = 0;r<i;r++)
            for(int g = 0;g<i;g++)
            {
                if(g!=r || r == 0 || g == 0)
                {
                    for(auto q : Q[i])
                        if(!Cumple(q,r,g,i))
                            DP[r][g][i] = 0;
                    DP[i+1][g][i] = (DP[i+1][g][i] + DP[r][g][i])%MOD;
                    DP[r][i+1][i] = (DP[r][i+1][i] + DP[r][g][i])%MOD;
                    DP[r][g][i+1] = (DP[r][g][i+1] + DP[r][g][i])%MOD;
                    if(i == N)
                        R = (R+DP[r][g][i])%MOD;

                }
            }
    }
    cout<<R<<endl;
}
