#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define for0(i,n) for (int i=0; i<n; i++)
#define forr(i,n) for (int i=n-1; i>=0; i--)
#define fori(i,a,b) for (int i=a; i<=b; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define read(x) int x; scanf("%d",&x);
#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

struct interval
{
    int l, r;
    int cnt;
};

vec(interval) intervals[305];
ll dp[305][305][305];

bool check_constraints(int ir, int ig, int ib)
{
    int idx = max(ir,max(ig,ib));
    iter(intervals[idx]) {
        int cnt = 0;
        if (ir >= it->l)
            cnt++;
        if (ig >= it->l)
            cnt++;
        if (ib >= it->l)
            cnt++;
        if (cnt != it->cnt)
            return false;
    }
    return true;
}

int main()
{
    #ifdef DEBUG
    freopen("RGB_sequence.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    read(N); read(M);
    for0(i,M) {
        int l,r,cnt;
        scanf("%d %d %d",&l,&r,&cnt);
        l--; r--;
        intervals[r].pb((interval){l,r,cnt});
    }

    ms(dp,0);
    for0(i,N+1) {
        for0(j,N+1) {
            dp[N][i][j] = dp[i][N][j] = dp[i][j][N] = 1;
        }
    }

    for (int ir=N-1; ir>=0; ir--) {
        for (int ig=N-1; ig>=0; ig--) {
            if (ig && ig == ir) continue;
            for (int ib=N-1; ib>=0; ib--) {
                if (ib && (ib == ir || ib == ig)) continue;

                int cur_idx = max(ir,max(ig,ib));
                if (check_constraints(cur_idx, ig-1, ib-1)) {
                    dp[ir][ig][ib] += dp[cur_idx+1][ig][ib];
                }
                if (check_constraints(ir-1, cur_idx, ib-1)) {
                    dp[ir][ig][ib] += dp[ir][cur_idx+1][ib];
                }
                if (check_constraints(ir-1, ig-1, cur_idx)) {
                    dp[ir][ig][ib] += dp[ir][ig][cur_idx+1];
                }
                //pr(ir) pr(ig) pr(ib) pr(dp[ir][ig][ib]) nl
                dp[ir][ig][ib] %= MOD;
            }
        }
    }

    cout<<dp[0][0][0]<<endl;
    return 0;
}


Measured memory_bytes: 221952