#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

ll dp[310][310][310];
bool ng12[310][310][1];
bool ng13[310][1][310];


int main(){
    ll N, M;
    cin >> N >> M;
    for(int i = 0; i < 310; i++){
        for(int j = 0; j < 310; j++){
            fill(dp[i][j], dp[i][j]+310, 0);
            ng12[i][j][0] = false;
            ng13[i][0][j] = false;
            if(i <= j){
                ng12[i][j][0] = true;
                ng13[i][0][j] = true;
            }
        }
    }

    for(int ii = 0; ii < M; ii++){
        int l, r, x;
        cin >> l >> r >> x;
        if(x == 1){
            for(int i = r; i >= l; i--){
                for(int j = i-1; j >= l; j--){
                    ng12[i][j][0] = true;
                }
            }
        }
        else if(x == 2){
            for(int i = 0; i < l; i++){
                ng12[r][i][0] = true;
            }
            for(int i = r; i >= l; i--){
                for(int j = i-1; j >= l; j--){
                    ng13[i][0][j] = true;
                }
            }
        }
        else{
            for(int j = 0; j <= l; j++){
                ng12[r][j][0] = true;
            }
            for(int j = 0; j < l; j++){
                ng13[r][0][j] = true;
            }
        }
    }

    if(ng12[1][0][0] || ng13[1][0][0]){
        cout << 0 << endl;
        return 0;
    }

    dp[1][0][0] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j < i; j++){
            for(int k = 0; k <= j; k++){
                if(!ng12[i+1][j][0] && !ng13[i+1][0][k]){
                    dp[i+1][j][k] = add(dp[i+1][j][k], dp[i][j][k]);
                }
                if(!ng12[i+1][i][0] && !ng13[i+1][0][k]){
                    dp[i+1][i][k] = add(dp[i+1][i][k], dp[i][j][k]);
                }
                if(!ng12[i+1][i][0] && !ng13[i+1][0][j]){
                    dp[i+1][i][j] = add(dp[i+1][i][j], dp[i][j][k]);
                }
            }
        }
    }


    ll res = 0;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            res = add(res, dp[N+1][i][j]);
        }
    }

    cout << res << endl;


    return 0;
}


Measured memory_bytes: 233856