#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

bool is_power_of_2(const LL x)  /* x >= 1 */
{ return (x & (x-1)) == 0; }    /* could be x == lowbit(x) */

const int mod = 1e9+7;
const int maxn = 303;
/*
 * dp(r,j,b)
 * r为red最后出现的位置
 * g为green最后出现的位置
 * b为blue最后出现的位置
 * dp[r][g][b]转移到 max{r,g,b}+1 的位置
 */
LL dp[maxn][maxn][maxn];
int N,M;
int L[maxn],R[maxn],X[maxn];
VI rule[maxn];

LL dfs(const int r, const int g, const int b)
{
    const int pos = max(r,max(g,b)) + 1;
    if (pos == N+1) {
        return 1;
    }
    LL& ans = dp[r][g][b];
    if (-1 == ans) {
        ans = 0;
        bool good[] = { true, true, true };
        FOR_ALL(i,rule[pos]) {
            int cnt;
            cnt = 1; cnt += L[*i] <= g; cnt += L[*i] <= b;
            good[0] &= (cnt == X[*i]);
            cnt = 1; cnt += L[*i] <= r; cnt += L[*i] <= b;
            good[1] &= (cnt == X[*i]);
            cnt = 1; cnt += L[*i] <= r; cnt += L[*i] <= g;
            good[2] &= (cnt == X[*i]);
        }
        if (good[0]) 
            ans += dfs(pos,g,b);
        if (good[1])
            ans += dfs(r,pos,b);
        if (good[2])
            ans += dfs(r,g,pos);
        ans %= mod;
    }
    return ans;
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    while (cin >> N >> M) {
        FOR(i,0,N+1)
            rule[i].clear();
        memset(dp,-1,sizeof(dp));
        FOR(i,0,M) {
            cin >> L[i] >> R[i] >> X[i];
            rule[R[i]].push_back(i);
        }
        const LL ans = dfs(0,0,0);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 217600