#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 300 + 5;

int dp[maxn][maxn][maxn];
vector<pair<int, int> > Op[maxn];

bool chk(int r, int g, int b) {
    int p = max(r, max(g, b));
    for(auto x : Op[p]) {
        int cnt = 0;
        if(x.first <= r) ++cnt;
        if(x.first <= g) ++cnt;
        if(x.first <= b) ++cnt;

        if(cnt != x.second) return false;
    }
    return true;
}
int main() {

    int n, m;
    //freopen("data.txt", "r", stdin);

    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++) {
        int l, r, x;
        cin >> l >> r >> x;
        Op[r].push_back(make_pair(l, x));
    }

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

    int v, ans = 0;
    for(int i = 0; i <= n; i++) 
        for(int j = 0; j <= n; j++)
            for(int k = 0; k <= n; k++) if((v = dp[i][j][k]) && chk(i, j, k)) {

                int p = max(i, max(j, k));
                if(p == n) (ans += v) %= mod;
                else {
                    ++p;
                    (dp[p][j][k] += v) %= mod;
                    (dp[i][p][k] += v) %= mod;
                    (dp[i][j][p] += v) %= mod;
                }
            }
    printf("%d\n", ans);

    return 0;
}
