const MOD: u32 = 1e9 as u32 + 7;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut rules = vec![vec![]; n + 1];
    for _ in 0..m {
        let l: usize = sc.read();
        let r: usize = sc.read();
        let x: usize = sc.read();

        if r == 1 && x != 1 {
            println!("0");
            return;
        }
        rules[r].push((l, x));
    }

    let mut dp = vec![vec![vec![0; n + 1]; n + 1]; n + 1];
    dp[0][0][1] = 1;
    dp[0][1][0] = 1;
    dp[1][0][0] = 1;
    for last in 1..n {
        for last1 in 0..last {
            for last2 in 0..last {
                if last1 == last2 && last1 != 0 {
                    continue;
                }
                for &(r, g, b) in [
                    (last, last1, last2),
                    (last1, last, last2),
                    (last1, last2, last),
                ]
                .iter()
                {
                    for &(nr, ng, nb) in
                        [(last + 1, g, b), (r, last + 1, b), (r, g, last + 1)].iter()
                    {
                        let mut ok = true;
                        for &(l, x) in rules[last + 1].iter() {
                            let mut count = 0;
                            if nr >= l {
                                count += 1;
                            }
                            if ng >= l {
                                count += 1;
                            }
                            if nb >= l {
                                count += 1;
                            }
                            if count != x {
                                ok = false;
                            }
                        }

                        if ok {
                            dp[nr][ng][nb] += dp[r][g][b];
                            if dp[nr][ng][nb] >= MOD {
                                dp[nr][ng][nb] -= MOD;
                            }
                        }
                    }
                }
            }
        }
    }

    let mut ans = 0;
    for i in 0..n {
        for j in 0..n {
            ans += dp[i][j][n];
            if ans >= MOD {
                ans -= MOD;
            }
            ans += dp[i][n][j];
            if ans >= MOD {
                ans -= MOD;
            }
            ans += dp[n][i][j];
            if ans >= MOD {
                ans -= MOD;
            }
        }
    }

    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 121084