import java.io.BufferedReader
import java.io.InputStreamReader

const val MOD = 1000000007L

fun main(omkar: Array<String>) {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    val line = jin.readLine().split(" ")
    val n = line[0].toInt()
    val m = line[1].toInt()
    val earliest = Array(4) { IntArray(n + 1) { Int.MAX_VALUE } }
    val latest = Array(4) { IntArray(n + 1) }
    for (j in 1..m) {
        val line = jin.readLine().split(" ")
        val l = line[0].toInt()
        val r = line[1].toInt()
        val x = line[2].toInt()
        earliest[x][r] = Math.min(earliest[x][r], l)
        latest[x][r] = Math.max(latest[x][r], l)
    }
    var dp = Array(n + 1) { LongArray(n + 1) }
    var dpAlt = Array(n + 1) { LongArray(n + 1) }
    dp[0][0] = 1L
    for (j1 in 0 until n) {
        dpAlt.forEach { it.fill(0L) }
        for (j2 in 0 until n) {
            for (j3 in 0 until n) {
                if (earliest[1][j1] > j2 && latest[2][j1] <= j2 && earliest[2][j1] > j3 && latest[3][j1] <= j3) {
                    // same as j1
                    dpAlt[j2][j3] += dp[j2][j3]
                    dpAlt[j2][j3] %= MOD
                    // same as j2
                    dpAlt[j1][j3] += dp[j2][j3]
                    dpAlt[j1][j3] %= MOD
                    // same as j3
                    dpAlt[j1][j2] += dp[j2][j3]
                    dpAlt[j1][j2] %= MOD
                }
            }
        }
        val temp = dp
        dp = dpAlt
        dpAlt = temp
    }
    var answer = 0L
    for (j2 in 0 until n) {
        for (j3 in 0 until n) {
            if (earliest[1][n] > j2 && latest[2][n] <= j2 && earliest[2][n] > j3 && latest[3][n] <= j3) {
                answer += dp[j2][j3]
                answer %= MOD
            }
        }
    }
    println(answer)
}