#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#ifndef INT_MAX
#  define INT_MAX std::numeric_limits<int>().max()
#endif
#ifndef INT_MIN
#  define INT_MIN std::numeric_limits<int>().min()
#endif
#define LL_MAX std::numeric_limits<ll>().max()
#define LL_MIN std::numeric_limits<ll>().min()
#define INF LL_MAX

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())

#define MAX_N   305
#define MAX_M   305

ll N, M;
ll dp[MAX_N][MAX_N][MAX_N];     // r, g, b まで色を塗ったときのパターン数
vector< pair< ll, pair<ll, ll> > > rule;    // r, l, x

int main()
{
    cin >> N >> M;

    REP(i, M) {
        ll l, r, x;
        cin >> l >> r >> x;
        rule.push_back( make_pair( r, make_pair(l, x) ) );
    }

    SORT(rule);

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

    dp[0][0][0] = 0;
    dp[1][0][0] = 1;
    dp[0][1][0] = 1;
    dp[0][0][1] = 1;

    for(ll middle=0; middle<=N; ++middle) {
        for(ll low=0; low<=middle; ++low) {
            for(ll k=0; k<rule.size(); ++k) {
                ll ri = rule[k].first;
                ll li = rule[k].second.first;
                ll xi = rule[k].second.second;
                if(middle == low && middle != 0) { continue; }
                if(ri <= middle){ continue; }
                if( (xi == 1 && (middle >= li || low >= li)) ||
                    (xi == 2 && (middle < li || low >= li)) ||
                    (xi == 3 && (middle < li || low < li)) )
                {
                    dp[ri][middle][low] = -1;
                    dp[ri][low][middle] = -1;
                    dp[middle][ri][low] = -1;
                    dp[low][ri][middle] = -1;
                    dp[middle][low][ri] = -1;
                    dp[low][middle][ri] = -1;
                }
            }
        }
    }

    for(ll r=0; r<=N; ++r) {
        for(ll g=0; g<=N; ++g) {
            for(ll b=0; b<=N; ++b) {
                if( (r == g && r != 0) ||
                    (r == b && r != 0) ||
                    (g == b && g != 0) )
                {
                    dp[r][g][b] = 0;
                    continue;
                }

                ll high = max(r, max(g, b));
                if(dp[r][g][b] <= 0) {
                    //dp[r][g][b] = 0;
                    continue;
                } else {
                    //printf("dp[%lld][%lld][%lld]: %lld\n", r, g, b, dp[r][g][b]);
                    if(dp[high+1][g][b] != -1) {
                        dp[high+1][g][b] += dp[r][g][b];
                        dp[high+1][g][b] %= 1000000007;
                    }
                    if(dp[r][high+1][b] != -1) {
                        dp[r][high+1][b] += dp[r][g][b];
                        dp[r][high+1][b] %= 1000000007;
                    }
                    if(dp[r][g][high+1] != -1) {
                        dp[r][g][high+1] += dp[r][g][b];
                        dp[r][g][high+1] %= 1000000007;
                    }
                }
            }
        }
    }

    ll ans = 0;
    for(ll i = 0; i <=N; ++i) {
        for(ll j=0; j<=N; ++j) {
            if(dp[N][i][j] > 0) { ans += dp[N][i][j]; }
            ans %= 1000000007;
            if(dp[i][N][j] > 0) { ans += dp[i][N][j]; }
            ans %= 1000000007;
            if(dp[i][j][N] > 0) { ans += dp[i][j][N]; }
            ans %= 1000000007;
        }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 221440