#include <bits/stdc++.h>


using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/

const int N = 305;

int dp[N][N][N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int n, m;
    cin>>n>>m;


    vector<vector<pair<int, int>>> a(n+1);

    for (int i = 0; i<m; i++)
    {
        int l, r, x;
        cin>>l>>r>>x;
        a[r].push_back(mp(l, x));
    }



    for (int i = 0; i<N; i++)
        for (int j = 0; j<N; j++)
            for (int k = 0; k<N; k++) dp[i][j][k] = 0;

    ll res = 0;

    dp[0][0][0] = 1;





    for (int r = 0; r<=n; r++)
        for (int g = 0; g<=n; g++)
            for (int b = 0; b<=n; b++)
            {
                bool check = true;
                if (r==g && r!=0)  check = false;
                if (r==b && r!=0)  check = false;
                if (b==g && b!=0)  check = false;
                vector<int> kek = {r, g, b};
                sort(kek.begin(), kek.end());
                int maxx = kek[2];



                for (auto it: a[maxx])
                {
                    int cur = 0;
                    while (it.first>kek[cur]) cur++;
                    if (it.second != 3-cur) check = false;
                }

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

                else
                {
                    if (maxx == n) res = add(res, dp[r][g][b]);
                    dp[maxx+1][g][b] = add(dp[maxx+1][g][b], dp[r][g][b]);
                    dp[r][maxx+1][b] = add(dp[r][maxx+1][b], dp[r][g][b]);
                    dp[r][g][maxx+1] = add(dp[r][g][maxx+1], dp[r][g][b]);
                }
            }

    /*for (int r = 0; r<=n; r++)
        for (int g = 0; g<=n; g++)
            for (int b = 0; b<=n; b++) if (dp[r][g][b]!=0)
            {
                cout<<r<<' '<<g<<' '<<b<<": "<<dp[r][g][b]<<endl;
            }*/

    cout<<res;




}


Measured memory_bytes: 111232