#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int n, m, l[328], r[328], x[328], d[328][328][328], z = 0;
bool b[328][328][328];

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) cin >> l[i] >> r[i] >> x[i];
    for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) for (int k = 0; k <= n; k++) {
        b[i][j][k] = 1;
        if (i && i == j) b[i][j][k] = 0;
        if (j && j == k) b[i][j][k] = 0;
        if (k && k == i) b[i][j][k] = 0;
    }
    for (int i = 1; i <= m; i++) {
        for (int j = 0; j < r[i]; j++) for (int k = 0; k < r[i]; k++) {
            int c = 1;
            if (j >= l[i]) c++;
            if (k >= l[i]) c++;
            if (c != x[i]) b[r[i]][j][k] = b[j][r[i]][k] = b[j][k][r[i]] = 0;
        }
    }
    //for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) for (int k = 0; k <= n; k++) if (b[i][j][k]) cout << i << ' ' << j << ' ' << k << '\n'; cout << '\n' << '\n';
    d[0][0][0] = 1;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < i; j++) for (int k = 0; k < i; k++) {
            if (b[i + 1][j][k]) {
                d[i + 1][j][k] += d[i][j][k];
                if (d[i + 1][j][k] >= mod) d[i + 1][j][k] -= mod;
            }
            if (b[i][i + 1][k]) {
                d[i][i + 1][k] += d[i][j][k];
                if (d[i][i + 1][k] >= mod) d[i][i + 1][k] -= mod;
            }
            if (b[i][j][i + 1]) {
                d[i][j][i + 1] += d[i][j][k];
                if (d[i][j][i + 1] >= mod) d[i][j][i + 1] -= mod;
            }
            //cout << i << ' ' << j << ' ' << k << ' ' << d[i][j][k] << '\n';
        }
        for (int j = 0; j <= i; j++) for (int k = 0; k < i; k++) {
            if (b[j][i + 1][k]) {
                d[j][i + 1][k] += d[j][i][k];
                if (d[j][i + 1][k] >= mod) d[j][i + 1][k] -= mod;
            }
            if (b[i + 1][i][k]) {
                d[i + 1][i][k] += d[j][i][k];
                if (d[i + 1][i][k] >= mod) d[i + 1][i][k] -= mod;
            }
            if (b[j][i][i + 1]) {
                d[j][i][i + 1] += d[j][i][k];
                if (d[j][i][i + 1] >= mod) d[j][i][i + 1] -= mod;
            }
            //cout << j << ' ' << i << ' ' << k << ' ' << d[j][i][k] << '\n';
        }
        for (int j = 0; j <= i; j++) for (int k = 0; k <= i; k++) {
            if (b[j][k][i + 1]) {
                d[j][k][i + 1] += d[j][k][i];
                if (d[j][k][i + 1] >= mod) d[j][k][i + 1] -= mod;
            }
            if (b[i + 1][k][i]) {
                d[i + 1][k][i] += d[j][k][i];
                if (d[i + 1][k][i] >= mod) d[i + 1][k][i] -= mod;
            }
            if (b[j][i + 1][i]) {
                d[j][i + 1][i] += d[j][k][i];
                if (d[j][i + 1][i] >= mod) d[j][i + 1][i] -= mod;
            }
            //cout << j << ' ' << k << ' ' << i << ' ' << d[j][k][i] << '\n';
        }
    }
    for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) for (int k = 0; k <= n; k++) if (max({i, j, k}) == n) {
        z += d[i][j][k];
        if (z >= mod) z -= mod;
    }
    cout << z << '\n';
}


Measured memory_bytes: 161920