#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int dp[303][303][303];

// i, x, l
int infomi[303][4], infoma[303][4];
int n, m;

vector<int> makevec(int a, int b, int c) {
    vector<int> ret;
    ret.push_back(a);
    ret.push_back(b);
    ret.push_back(c);
    ret.push_back(INF);
    sort(ret.begin(), ret.end());
    return ret;
}

int di[] = {1, 0, 0}, dj[] = {0, 1, 0}, dk[] = {0, 0, 1};
void chadd(int &a, int b) {a = madd(a, b);}

void pr(int a, int b, int c) {printf("dp[%lld][%lld][%lld] = %lld\n", a, b, c, dp[a][b][c]);}

signed main() {
    cin >> n >> m;
    repq(i,0,n) rep(j,0,4) {
        infomi[i][j] = INF;
        infoma[i][j] = -1;
    }
    rep(i,0,m) {
        int l, r, x; cin >> l >> r >> x;
        infomi[r][x] = min(infomi[r][x], l);
        infoma[r][x] = max(infoma[r][x], l);
    }

    dp[0][0][0] = 1;
    int ans = 0;
    rep(i,0,n) rep(j,0,n) rep(k,0,n) {
        rep(s,0,3) {
            int z = max({i, j, k}) + 1;
            int ni = z*di[s] + (di[s]^1) * i;
            int nj = z*dj[s] + (dj[s]^1) * j;
            int nk = z*dk[s] + (dk[s]^1) * k;
            int x, y;
            if(ni == z) x = min(nj, nk), y = max(nj, nk);
            if(nj == z) x = min(ni, nk), y = max(ni, nk);
            if(nk == z) x = min(ni, nj), y = max(ni, nj);

            bool ok = true;
            if(infoma[z][3] > x) ok = false;
            if(infomi[z][2] <= x) ok = false;
            if(infoma[z][2] > y) ok = false;
            if(infomi[z][1] <= y) ok = false;
            if(ok) {
                // printf("ok: (%lld, %lld, %lld)\n", ni, nj, nk);
                if(z == n) chadd(ans, dp[i][j][k]);
                // printf("add: from (%lld, %lld, %lld) -> to (%lld, %lld, %lld), val = %lld + %lld\n", i, j, k, ni, nj, nk, dp[ni][nj][nk], dp[i][j][k]);
                chadd(dp[ni][nj][nk], dp[i][j][k]);
            }
        }
    }
    // repq(i,0,n) repq(j,0,n) repq(k,0,n) pr(i, j, k);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 217472