#include <bits/stdc++.h>

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define pb push_back
#define fst first
#define snd second
#define endl '\n'

typedef long long ll;

const int N = 303;
const int M = 1e9 + 7;

vector<pair<int, int>> g[N];

int n, m;

ll dp[N][N][N];

ll sum(ll a, ll b){
    ll ans=(a+b); if(ans>=M) ans-=M;
    return ans;
}

ll solve(int i, int j, int k) {
    ll &r = dp[i][j][k];
    if(r != -1) return r;
    int p = max({i, j, k}) + 1;
    for(auto x : g[p]) {
        int c = (i >= x.fst) + (j >= x.fst) + (k >= x.fst);
        if(c != x.snd) return r = 0;
    }
    if(p == n + 1) return r = 1;
    ll res = sum(sum(solve(p, j, k), solve(i, p, k)), solve(i, j, p));
    return r = res;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    memset(dp, -1, sizeof dp);
    fore(i, 0, m) {
        int l, r, x; cin >> l >> r >> x;
        g[r + 1].pb({l, x});
    }
    fore(i, 2, n + 2) sort(g[i].begin(), g[i].end());
    cout << solve(0, 0, 0) << endl;
    return 0;
}