#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 305;

ll dp[MAX_N][MAX_N][MAX_N];
vp vec[MAX_N];

void extgcd(int a,int b, int& x,int& y)
{
	if(b != 0){
		extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
}

int mod_inverse(int a,int m)
{
	int x,y;
	extgcd(a,m,x,y);
	return (m + x % m) % m;
}

ll add(ll x,ll y)
{
    return (x + y)%MOD;
}

ll sub(ll x,ll y)
{
    return (x+MOD-y)%MOD;
}

ll mul(ll x,ll y)
{
    return x*y%MOD;
}

bool ok(int i,int j,int k)
{
    rep(l,len(vec[i])){
        if(vec[i][l].se == 1){
            if(j > vec[i][l].fi || k > vec[i][l].fi){
                return false;
            }
        }else if(vec[i][l].se == 2){
            if((j > vec[i][l].fi && k > vec[i][l].fi) || (j <= vec[i][l].fi && k <= vec[i][l].fi)){
                return false;
            }
        }else{
            if(j <= vec[i][l].fi || k <= vec[i][l].fi){
                return false;
            }
        }
    }
    return true;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        vec[b+2].pb(P(a+2,c));
    }
    dp[0][1][2] = 1;
    rep(i,n+3){
        rep(j,i){
            rep(k,i){
                if(dp[i][j][k]){
                    if(ok(i,j,k)){
                        dp[i+1][j][k] = add(dp[i+1][j][k],dp[i][j][k]);
                    }
                }
                if(dp[j][i][k]){
                    if(ok(i,i,k)){
                        dp[i+1][i][k] = add(dp[i+1][i][k],dp[j][i][k]);
                    }
                }
                if(dp[j][k][i]){
                    if(ok(i,k,i)){
                        dp[i+1][k][i] = add(dp[i+1][k][i],dp[j][k][i]);
                    }
                }

                if(dp[j][i][k]){
                    if(ok(i,j,k)){
                        dp[j][i+1][k] = add(dp[j][i+1][k],dp[j][i][k]);
                    }
                }
                if(dp[i][j][k]){
                    if(ok(i,i,k)){
                        dp[i][i+1][k] = add(dp[i][i+1][k],dp[i][j][k]);
                    }
                }
                if(dp[j][k][i]){
                    if(ok(i,i,j)){
                        dp[j][i+1][i] = add(dp[j][i+1][i],dp[j][k][i]);
                    }
                }

                if(dp[j][k][i]){
                    if(ok(i,j,k)){
                        dp[j][k][i+1] = add(dp[j][k][i+1],dp[j][k][i]);
                    }
                }
                if(dp[j][i][k]){
                    if(ok(i,i,j)){
                        dp[j][i][i+1] = add(dp[j][i][i+1],dp[j][i][k]);
                    }
                }
                if(dp[i][j][k]){
                    if(ok(i,i,j)){
                        dp[i][j][i+1] = add(dp[i][j][i+1],dp[i][j][k]);
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(j,n+3){
        rep(k,n+3){
            ans = add(ans,dp[n+3][j][k]);
            ans = add(ans,dp[j][n+3][k]);
            ans = add(ans,dp[j][k][n+3]);
        }
    }
    cout << mul(ans,mod_inverse(3,MOD)) << "\n";
    return 0;
}


Measured memory_bytes: 220160