#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define INF (1LL<<60)
typedef pair<int,int> P;

ll dp[301][301][301];

int main(){
    int n;
    int m;
    cin >> n >> m;
    vector<vector<pair<int,int> > > v(n+1);
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        v[b].push_back(MP(a,c));
    }
    dp[0][0][0] = 1;
    dp[0][0][1] = 1;
    dp[0][1][0] = 1;
    dp[1][0][0] = 1;
    ll res = 0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=n;k++){
                if(i+j+k==0)continue;
                
                if((i==j&&i!=0)||(j==k&&j!=0)||(i==k&&i!=0))continue;
                if(max({i,j,k})==i){
                    if(i==j+1){
                        for(int l=0;l<=j-1;l++){
                            dp[i][j][k] += dp[l][j][k];
                            dp[i][j][k] %= mod;
                        }
                    }else if(i==k+1){
                        for(int l=0;l<=k-1;l++){
                            dp[i][j][k] += dp[l][j][k];
                            dp[i][j][k] %= mod;
                        }
                    }else{
                        dp[i][j][k] += dp[i-1][j][k];
                        dp[i][j][k] %= mod;
                    }
                    for(auto x:v[i]){
                        int cnt = 0;
                        if(i>=x.first)cnt++;
                        if(j>=x.first)cnt++;
                        if(k>=x.first)cnt++;
                        if(cnt!=x.second)dp[i][j][k] = 0;
                    }
                }else if(max({i,j,k})==j){
                    if(j==i+1){
                        for(int l=0;l<=i-1;l++){
                            dp[i][j][k] += dp[i][l][k];
                            dp[i][j][k] %= mod;
                        }
                    }else if(j==k+1){
                        for(int l=0;l<=k-1;l++){
                            dp[i][j][k] += dp[i][l][k];
                            dp[i][j][k] %= mod;
                        }
                    }else{
                        dp[i][j][k] += dp[i][j-1][k];
                        dp[i][j][k] %= mod;
                    }
                    for(auto x:v[j]){
                        int cnt = 0;
                        if(i>=x.first)cnt++;
                        if(j>=x.first)cnt++;
                        if(k>=x.first)cnt++;
                        if(cnt!=x.second)dp[i][j][k] = 0;
                    }
                }else{
                    if(k==i+1){
                        for(int l=0;l<=i-1;l++){
                            dp[i][j][k] += dp[i][j][l];
                            dp[i][j][k] %= mod;
                        }
                    }else if(k==j+1){
                        for(int l=0;l<=j-1;l++){
                            dp[i][j][k] += dp[i][j][l];
                            dp[i][j][k] %= mod;
                        }
                    }else{
                        dp[i][j][k] += dp[i][j][k-1];
                        dp[i][j][k] %= mod;
                    }
                    for(auto x:v[k]){
                        int cnt = 0;
                        if(i>=x.first)cnt++;
                        if(j>=x.first)cnt++;
                        if(k>=x.first)cnt++;
                        if(cnt!=x.second)dp[i][j][k] = 0;
                    }
                }
                if(max({i,j,k})==n){
                    res += dp[i][j][k];
                    res %= mod;
                }
                //cerr << i << " " << j << " " << k << " " << dp[i][j][k] << endl;
            }
        }   
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 213376