#include "bits/stdc++.h"
using namespace std;
typedef long long li;


template <long long mod>
struct modint {
    long long x;

    modint<mod>(): x(0LL) {}
    modint<mod>(const long long _data) {
        if (_data < 0) {
            x = (_data % mod + mod) % mod;
        } else if (_data >= mod) {
            x = _data % mod;
        } else {
            x = _data;
        }
    }

    bool operator==(const modint<mod>& op) const {
        return x == op.x;
    }

    bool operator!=(const modint<mod>& op) const {
        return !((*this) == op);
    }

    modint<mod> operator-() const {
        if (x == 0) {
            return modint(0);
        }
        return modint(mod - x);
    }

    modint<mod> operator+(const modint<mod>& op) const {
        const long long newdata = x + op.x;
        if (newdata >= mod) {
            return modint<mod>(newdata - mod);
        } else {
            return modint<mod>(newdata);
        }
    }

    modint<mod> operator-(const modint<mod>& op) const {
        return *this + (-op);
    }

    modint<mod> operator*(const modint<mod>& op) const {
        return modint<mod>(x * op.x % mod);
    }

    modint<mod> pow(const long long n) const {
        if (n == 0) {
            return modint<mod>(1);
        }
        modint<mod> sq = pow(n / 2);
        if (n & 1) {
            return (*this) * sq * sq;
        } else {
            return sq * sq;
        }
    }

    modint<mod> inverse() const {
        return pow(mod - 2);
    }

    modint<mod> operator/(const modint<mod>& op) const {
        return (*this) * op.inverse();
    }

    friend modint<mod> operator/(const long long dividend, const modint<mod>& divisor) {
        return modint<mod>(dividend) / divisor;
    }

    static modint<mod> factorial(const long long n) {
        static std::vector<modint<mod>> cache(1, 1);

        while (cache.size() <= n) {
            modint<mod> next = cache.back() * cache.size();
            cache.push_back(next);
        }
        return cache[n];
    }

    static modint<mod> combination(const long long n, const long long k) {
        if (k < 0 || n < k) {
            return modint<mod>(0);
        }

        if (n < 1e6) {
            return factorial(n) / (factorial(k) * factorial(n - k));
        }

        modint<mod> ret(1);
        for (int i = 1; i <= k; ++i) {
            ret = ret * modint<mod>(n - i + 1) / modint<mod>(i);
        }
        return ret;
    }
};

typedef modint<1000000007> mint;


struct constraint {
    li l, r, x;
    constraint(li _l, li _r, li _x) {
        l = _l;
        r = _r;
        x = _x;
    }
};

const int MAX_N = 301;
mint dp[MAX_N][MAX_N][MAX_N];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    li n, m;
    cin >> n >> m;

    map<li, vector<constraint>> constraints;
    for (int i = 0; i < m; ++i) {
        li l, r, x;
        cin >> l >> r >> x;
        constraints[r].emplace_back(l, r, x);
    }

    for (int i = 0; i < MAX_N; ++i) {
        for (int j = 0; j < MAX_N; ++j) {
            for (int k = 0; k < MAX_N; ++k) {
                dp[i][j][k] = 0;
            }
        }
    }
    dp[0][0][0] = 1;

    mint ans = 0;
    for (int k = 0; k <= n; ++k) {
        for (int j = 0; j < k || j == 0; ++j) {
            for (int i = 0; i < j || i == 0; ++i) {
                bool ok = true;
                for (auto & constr: constraints[k]) {
                    int colors = 1;
                    if (j >= constr.l) {
                        colors += 1;
                    }
                    if (i >= constr.l) {
                        colors += 1;
                    }
                    ok &= colors == constr.x;
                }
                vector<int> state ={i, j, k};
                do {
                    const int r = state[0];
                    const int g = state[1];
                    const int b = state[2];
                    if (not ok) {
                        dp[r][g][b] = 0;
                    }
                    if (k < n) {
                        for (int c = 0; c < 3; ++c) {
                            const int nr = (c == 0) ? k + 1 : r;
                            const int ng = (c == 1) ? k + 1 : g;
                            const int nb = (c == 2) ? k + 1 : b;
                            dp[nr][ng][nb] = dp[nr][ng][nb] + dp[r][g][b];
                        }
                    } else {
                        ans = ans + dp[r][g][b];
                    }
                } while (next_permutation(state.begin(), state.end()));
            }
        }
    }

    cout << ans.x << endl;

    return 0;
}

Measured memory_bytes: 213376