/***********************************************
#
#      Filename: e.cpp
#
#        Author: Comsyl - ylsong15@fudan.edu.cn
#   Description: 把情况归类，计数
#        Create: 2017-05-27 00:13:27
***********************************************/
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000000 + 7;
int N, M;
int dp[310][310][310];

inline int add(int x, int y) {
    if (x == -1 || y == -1) return -1;
    return (x + y) >= MOD ? (x + y - MOD) : (x + y);
}

int main()
{
    cin >> N >> M;
    int li, ri, xi;
    for (int it = 0; it < M; ++ it) {
        cin >> li >> ri >> xi;
        if (xi == 1) {
            for (int i = 0; i <= li-1; ++ i) // 2
                for (int j = li; j <= ri-1; ++ j)
                    dp[ri][i][j] = dp[ri][j][i] = dp[i][ri][j] = dp[j][ri][i] = dp[i][j][ri] = dp[j][i][ri] = -1;
            for (int i = li; i <= ri-1; ++ i) // 3
                for (int j = li; j <= ri-1; ++ j)
                    dp[ri][i][j] = dp[ri][j][i] = dp[i][ri][j] = dp[j][ri][i] = dp[i][j][ri] = dp[j][i][ri] = -1;
        } else if (xi == 2) {
            for (int i = 0; i <= li-1; ++ i) // 1
                for (int j = 0; j <= li-1; ++ j)
                    dp[ri][i][j] = dp[ri][j][i] = dp[i][ri][j] = dp[j][ri][i] = dp[i][j][ri] = dp[j][i][ri] = -1;
            for (int i = li; i <= ri-1; ++ i) // 3
                for (int j = li; j <= ri-1; ++ j)
                    dp[ri][i][j] = dp[ri][j][i] = dp[i][ri][j] = dp[j][ri][i] = dp[i][j][ri] = dp[j][i][ri] = -1;
        } else if (xi == 3) {
            for (int i = 0; i <= li-1; ++ i) // 1
                for (int j = 0; j <= li-1; ++ j)
                    dp[ri][i][j] = dp[ri][j][i] = dp[i][ri][j] = dp[j][ri][i] = dp[i][j][ri] = dp[j][i][ri] = -1;
            for (int i = 0; i <= li-1; ++ i) // 2
                for (int j = li; j <= ri-1; ++ j)
                    dp[ri][i][j] = dp[ri][j][i] = dp[i][ri][j] = dp[j][ri][i] = dp[i][j][ri] = dp[j][i][ri] = -1;
        }
    }

    if (dp[1][0][0] == -1) {
        cout << 0 << endl;
        return 0;
    }
    dp[1][0][0] = dp[0][1][0] = dp[0][0][1] = 1;
    for (int k = 1; k < N; ++ k) {
        for (int i = 0; i < k; ++ i) {
            for (int j = 0; j < k; ++ j) {
                if (i && i == j) continue;
                int up = dp[k][i][j];
                if (up == -1) continue;
                dp[k+1][i][j] = add(dp[k+1][i][j], up);
                dp[k][k+1][j] = add(dp[k][k+1][j], up);
                dp[k][i][k+1] = add(dp[k][i][k+1], up);

                dp[i][k+1][j] = add(dp[i][k+1][j], up);
                dp[k+1][k][j] = add(dp[k+1][k][j], up);
                dp[i][k][k+1] = add(dp[i][k][k+1], up);

                dp[i][j][k+1] = add(dp[i][j][k+1], up);
                dp[k+1][j][k] = add(dp[k+1][j][k], up);
                dp[i][k+1][k] = add(dp[i][k+1][k], up);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < N; ++ i) {
        for (int j = 0; j < N; ++ j) {
            if ((i && i == j) || dp[N][i][j] == -1) continue;
            ans = add(ans, dp[N][i][j]);
            ans = add(ans, dp[i][N][j]);
            ans = add(ans, dp[i][j][N]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 114944