#include<cstdio>
#include<vector>
using std::vector;
const int mod = 1e9+7;
int f[305][305][305];
struct Element{
    int l,r;
    int x;
};
Element a[305];
vector<int>seg[3][305];
int bit[3][305];
int spBit[305];

void change(int p,int v,int n,int bit[]){
    while(p<=n){
        bit[p] += v;
        p += p&-p;
    }
}

int ask(int p,int bit[]){
    int res = 0;
    while(p!=0){
        res += bit[p];
        p -= p&-p;
    }
    return res;
}

int segSum(int l,int r,int bit[]){
    if(l>r) return 0;
    else return ask(r,bit)-ask(l-1,bit);
}

int min(int a,int b){ return a>b?b:a; }

int max(int a,int b){ return a>b?a:b; }

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int ok = 1;
    for(int i = 1; i <= m; i++){
        scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].x);
        if(a[i].r-a[i].l+1<a[i].x) ok = 0;
        seg[a[i].x-1][a[i].r].push_back(a[i].l);
        change(a[i].l,1,n,bit[a[i].x-1]);
    }
    if(!ok){
        printf("0\n");
        return 0;
    }
    f[1][0][0] = f[0][1][0] = f[0][0][1] = 1;
    for(int i = 1; i <= n-1; i++){
        for(int j = 0; j < 3; j++){
            for(int l: seg[j][i]){
                change(l,-1,n,bit[j]);
            }
        }
        int max2 = -1;
        for(int l: seg[1][i+1]) if(max2<l) max2 = l;
        //printf("max2 = %d\n",max2);
        for(int j = 1; j <= n; j++) spBit[j] = 0;
        for(int l: seg[2][i+1]) change(l,1,n,spBit);
        for(int j = 0; j < i; j++){
            for(int k = 0; k < i; k++){
                if(j && k && j==k) continue;
                //f[i][j][k], f[j][i][k], f[j][k][i]
                int ban[3] = {0,0,0}; //i,j,k
                /*for(int t = 1; t <= m; t++){
                    int l = a[t].l, r = a[t].r, x = a[t].x;
                    if(l>i || r<=i) continue;
                    else{
                        if(x==1) ban[1] = ban[2] = 1;
                        else if(x==2){
                            if(j>=l && k>=l) ban[0] = ban[1] = ban[2] = 1;
                            else if(j>=l) ban[2] = 1;
                            else if(k>=l) ban[1] = 1;
                            else{
                                //sp check
                                if(r==i+1) ban[0] = 1;
                            }
                        }
                        else{
                            if(r==i+1){
                                if(j>=l && k>=l){}
                                else if(j>=l) ban[0] = ban[1] = 1;
                                else if(k>=l) ban[0] = ban[2] = 1;
                                else ban[0] = ban[1] = ban[2] = 1;
                            }
                        }
                    }
                }*/
                //x=1
                if(segSum(1,i,bit[0])!=0) ban[1] = ban[2] = 1;
                //x=2
                int lower = min(j,k), upper = max(j,k);
                if(segSum(1,lower,bit[1])!=0) ban[0] = ban[1] = ban[2] = 1;
                if(j<k && segSum(j+1,k,bit[1])!=0) ban[1] = 1;
                if(k<j && segSum(k+1,j,bit[1])!=0) ban[2] = 1;
                if(max2!=-1 && max2>upper) ban[0] = 1;
                //x=3
                if(j<k && segSum(j+1,k,spBit)!=0) ban[0] = ban[2] = 1;
                if(k<j && segSum(k+1,j,spBit)!=0) ban[0] = ban[1] = 1;
                if(segSum(upper+1,i,spBit)!=0) ban[0] = ban[1] = ban[2] = 1;
                //f[i][j][k], f[j][i][k], f[j][k][i]
                /*printf("i = %d, j = %d, k = %d\n",i,j,k);
                for(int t = 0; t < 3; t++) printf("ban[%d] = %d ",t,ban[t]);
                printf("\n");*/
                if(!ban[0]){
                    (f[i+1][j][k] += f[i][j][k]) %= mod; 
                    (f[j][i+1][k] += f[j][i][k]) %= mod;
                    (f[j][k][i+1] += f[j][k][i]) %= mod;
                }
                if(!ban[1]){
                    (f[i][i+1][k] += f[i][j][k]) %= mod;
                    (f[i+1][i][k] += f[j][i][k]) %= mod;
                    (f[i+1][k][i] += f[j][k][i]) %= mod;
                }
                if(!ban[2]){
                    (f[i][j][i+1] += f[i][j][k]) %= mod;
                    (f[j][i][i+1] += f[j][i][k]) %= mod;
                    (f[j][i+1][i] += f[j][k][i]) %= mod;
                }
            }
        }
    }
    long long ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            ans += f[n][i][j]; if(ans>=mod) ans -= mod;
            ans += f[i][n][j]; if(ans>=mod) ans -= mod;
            ans += f[i][j][n]; if(ans>=mod) ans -= mod;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 112356