import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable long mod = 10^^9 + 7;
alias Pair = Tuple!(int, "l", int, "x");

void main(){
    int N, M;
    int li, ri, xi;
    readVars(N, M);

    auto cond = new Pair[][](N + 1);

    foreach(i ; 0 .. M){
        readVars(li, ri, xi);
        cond[ri] ~= Pair(li, xi);
    }

    //writeln(cond);

    auto dp = new int[][][](N + 1, N + 1, N + 1);
    dp[0][0][0] = 1;

    int k, v;

    foreach(r ; 0 .. N + 1){
        foreach(g ; 0 .. N + 1){
            foreach(b ; 0 .. N + 1){
                k = max(r, g, b);
                bool flag;

                foreach(c ; cond[k]){
                    v = (c.l <= r) + (c.l <= g) + (c.l <= b);

                    if (v != c.x) {
                        flag = true;
                        break;
                    }
                }

                if (flag){
                    dp[r][g][b] = 0;
                    continue;
                }

                if (k + 1 <= N) {
                    dp[k + 1][g][b] = (dp[k + 1][g][b] + dp[r][g][b]) % mod;
                    dp[r][k + 1][b] = (dp[r][k + 1][b] + dp[r][g][b]) % mod;
                    dp[r][g][k + 1] = (dp[r][g][k + 1] + dp[r][g][b]) % mod;
                }
            }
        }
    }

    int ans;

    foreach(r ; 0 .. N + 1){
        foreach(g ; 0 .. N + 1){
            ans = (ans + dp[r][g][N]) % mod;
        }
    }

    foreach(r ; 0 .. N + 1){
        foreach(b ; 0 .. N + 1){
            ans = (ans + dp[r][N][b]) % mod;
        }
    }

    foreach(g ; 0 .. N + 1){
        foreach(b ; 0 .. N + 1){
            ans = (ans + dp[N][g][b]) % mod;
        }
    }

    writeln(ans);

}

void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}