#include <bits/stdc++.h>

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"
#include "profile.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define profile(X) LOG_DURATION(X)
#else
#define debug(...) 42
#define profile(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
//const ll MOD = 924844033;
const ld PI = 3.141592653589793;
const int maxn = 600001;
const int MOD = 1e9 + 7;
using cd = complex<double>;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

int dp[301][301][301]; // rgb
int used[301][301][301]; // rgb
signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    profile("all");
    auto solve = [](int _) {
        int n;
        cin >> n;
        int m;
        cin >> m;
        vector<int> l(m + 1);
        vector<int> r(m + 1);
        vector<int> x(m + 1);

        for (int i = 1; i <= m; ++i) {
            cin >> l[i] >> r[i] >> x[i];
        }
        vector<vector<int>> ends(n + 2);
        for (int i = 1; i <= m; ++i) {
            ends[r[i]].push_back(i);
        }
        queue<tuple<int, int, int>> q;
        q.emplace(0, 0, 0);
        used[0][0][0] = 1;
        dp[0][0][0] = 1;
        while (!q.empty()) {
            int red, green, blue;
            tie(red, green, blue) = q.front();
            debug(red, green, blue, dp[red][green][blue]);
            q.pop();
            if (!dp[red][green][blue]) {
                continue;
            }
            int mx = max({red, green, blue});
            if (mx == n) {
                continue;
            }
            // red

            auto upd = [&](int nred, int ngreen, int nblue) {
                bool ok = true;
                for (int id:ends[mx + 1]) {
                    int cur = (nred >= l[id]) + (ngreen >= l[id]) + (nblue >= l[id]);
                    if (cur != x[id]) {
                        ok = false;
                    }
                }
                if (ok) {
                    dp[nred][ngreen][nblue] += dp[red][green][blue];
                    if (dp[nred][ngreen][nblue] >= MOD) {
                        dp[nred][ngreen][nblue] -= MOD;
                    }
                }
                if (!used[nred][ngreen][nblue]) {
                    used[nred][ngreen][nblue] = 1;
                    q.emplace(nred, ngreen, nblue);
                }
            };
            upd(mx+1, green, blue);
            upd(red, mx+1, blue);
            upd(red, green, mx+1);
        }
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {

                ans += dp[i][j][n];
                if (ans >= MOD) {
                    ans -= MOD;
                }
                ans += dp[n][i][j];
                if (ans >= MOD) {
                    ans -= MOD;
                }
                ans += dp[i][n][j];
                if (ans >= MOD) {
                    ans -= MOD;
                }
            }
        }
        cout << ans;
    };


    fast_io();
    cout.precision(9);
    cout << fixed;

    solve(1);


}


Measured memory_bytes: 216704