### BUGGY CODE ###

import sys
readline = sys.stdin.readline

def viol(c2, c3, l, x):
    res = False
    if x == 1:
        if not c2 < l:
            res = True
    elif x == 2:
        if not c3 < l <= c2:
            res = True
    else:
        if not l <= c3:
            res = True
    return res
MOD = 10**9+7
N, M = map(int, readline().split())
limit = [[] for _ in range(N+3)]

for _ in range(M):
    l, r, x = map(int, readline().split())
    limit[r+2].append((l+2, x))


dp = [[[0]*(N+3) for _ in range(N+3)] for _ in range(N+3)]
dp[0][1][2] = 1

for i in range(2, N+2):
    
    r = i
    for g in range(r):
        for b in range(g):
            d = dp[r][g][b]
            dp[r+1][g][b] = (dp[r+1][g][b] + d)%MOD
            dp[r][r+1][b] = (dp[r][r+1][b] + d)%MOD
            dp[r][g][r+1] = (dp[r][g][r+1] + d)%MOD
    for b in range(r):
        for g in range(b):
            d = dp[r][g][b]
            dp[r+1][g][b] = (dp[r+1][g][b] + d)%MOD
            dp[r][r+1][b] = (dp[r][r+1][b] + d)%MOD
            dp[r][g][r+1] = (dp[r][g][r+1] + d)%MOD
    
    g = i
    for r in range(g):
        for b in range(r):
            d = dp[r][g][b]
            dp[g+1][g][b] = (dp[g+1][g][b] + d)%MOD
            dp[r][g+1][b] = (dp[r][g+1][b] + d)%MOD
            dp[r][g][g+1] = (dp[r][g][g+1] + d)%MOD
    for b in range(g):
        for r in range(b):
            d = dp[r][g][b]
            dp[g+1][g][b] = (dp[g+1][g][b] + d)%MOD
            dp[r][g+1][b] = (dp[r][g+1][b] + d)%MOD
            dp[r][g][g+1] = (dp[r][g][g+1] + d)%MOD
    
    b = i
    for r in range(b):
        for g in range(r):
            d = dp[r][g][b]
            dp[b+1][g][b] = (dp[b+1][g][b] + d)%MOD
            dp[r][b+1][b] = (dp[r][b+1][b] + d)%MOD
            dp[r][g][b+1] = (dp[r][g][b+1] + d)%MOD
    for g in range(b):
        for r in range(g):
            d = dp[r][g][b]
            dp[b+1][g][b] = (dp[b+1][g][b] + d)%MOD
            dp[r][b+1][b] = (dp[r][b+1][b] + d)%MOD
            dp[r][g][b+1] = (dp[r][g][b+1] + d)%MOD
    
    for l, x in limit[i+1]:
        r = i+1
        for g in range(r):
            for b in range(g):
                if viol(g, b, l, x):
                    dp[r][g][b] = 0
        for b in range(r):
            for g in range(b):
                if viol(b, g, l, x):
                    dp[r][g][b] = 0
        g = i+1
        for r in range(g):
            for b in range(r):
                if viol(r, b, l, x):
                    dp[r][g][b] = 0
        for b in range(g):
            for r in range(b):
                if viol(b, r, l, x):
                    dp[r][g][b] = 0
        b = i+1
        for r in range(b):
            for g in range(r):
                if viol(r, g, l, x):
                    dp[r][g][b] = 0
        for g in range(b):
            for r in range(g):
                if viol(g, r, l, x):
                    dp[r][g][b] = 0
res = 0
for r in range(N+3):
    for g in range(N+3):
        for b in range(N+3):
            if max(r, g, b) == 2+N:
                res = (res + dp[r][g][b])%MOD
print(res)


### FIXED CODE ###

import sys
readline = sys.stdin.readline

def viol(c2, c3, l, x):
    res = False
    if x == 1:
        if not c2 < l:
            res = True
    elif x == 2:
        if not c3 < l <= c2:
            res = True
    else:
        if not l <= c3:
            res = True
    return res
MOD = 10**9+7
N, M = map(int, readline().split())
limit = [[] for _ in range(N+3)]

for _ in range(M):
    l, r, x = map(int, readline().split())
    limit[r+2].append((l+2, x))

dp = [[0, 0], [1, 0]]

for i in range(2, N+2):    
    dp2 = [[0]*(i+1) for _ in range(i+1)]
    r = i
    for g in range(r):
        for b in range(g):
            d = dp[g][b]
            dp2[g][b] = (dp2[g][b] + d)%MOD
            dp2[r][b] = (dp2[r][b] + d)%MOD
            dp2[r][g] = (dp2[r][g] + d)%MOD
    for l, x in limit[i+1]:
        r = i+1
        for g in range(r):
            for b in range(g):
                if viol(g, b, l, x):
                    dp2[g][b] = 0
    dp = [d[:] for d in dp2]
    
res = 0
for g in range(N+2):
    for b in range(g):
        res = (res + dp[g][b]) % MOD
print(res)