#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 305;
const long long MOD = 1e9+7;
long long ans;
vector<pair<long long,long long>> v1[MAXN];
long long dp[MAXN][MAXN][MAXN];
int main(){
    long long n,m;
    cin>>n>>m;
    for(long long i=1;i<=m;i++){
        long long l,r,x;
        cin>>l>>r>>x;
        v1[r].push_back(make_pair(l,x));
    }
    dp[0][0][0] = 1;
    for(long long i=0;i<=n;i++){
        for(long long j=0;j<=n;j++){
            for(long long k=0;k<=n;k++){
                if(dp[i][j][k] == 0){
                    continue;
                }
                long long rec = max(i,max(j,k));
                bool b1 = true;
                bool b2 = true;
                bool b3= true;
                for(auto x:v1[rec+1]){
                    long long cnt = 0;
                    if(x.first<=rec+1){
                        cnt++;
                    }
                    if(x.first<=j){
                        cnt++;
                    }
                    if(x.first<=k){
                        cnt++;
                    }

                    if(cnt!=x.second){
                        b1 = false;
                    }
                }
                for(auto x:v1[rec+1]){
                    long long cnt = 0;
                    if(x.first<=i){
                        cnt++;
                    }
                    if(x.first<=rec+1){
                        cnt++;
                    }
                    if(x.first<=k){
                        cnt++;
                    }

                    if(cnt!=x.second){
                        b2 = false;
                    }
                }
                for(auto x:v1[rec+1]){
                    long long cnt = 0;
                    if(x.first<=i){
                        cnt++;
                    }
                    if(x.first<=j){
                        cnt++;
                    }
                    if(x.first<=rec+1){
                        cnt++;
                    }

                    if(cnt!=x.second){
                        b3 = false;
                    }
                }
                if(b1){
                    dp[rec+1][j][k]+=dp[i][j][k];
                    dp[rec+1][j][k]%=MOD;
                }
                if(b2){
                    dp[i][rec+1][k]+=dp[i][j][k];
                    dp[i][rec+1][k]%=MOD;
                }
                if(b3){
                    dp[i][j][rec+1]+=dp[i][j][k];
                    dp[i][j][rec+1]%=MOD;
                }

              //  cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
            }
        }
    }
    for(long long i=0;i<=n;i++){
        for(long long j=0;j<=n;j++){
            for(long long k=0;k<=n;k++){
                if(i==j && i){
                    continue;
                }
                if(i==k && i){
                    continue;
                }
                if(j==k && j){
                    continue;
                }

                if(i==n||j==n||k==n){
                    ans+=dp[i][j][k];
                    ans%=MOD;
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 221440