#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 300, MAX_M = 300, MOD = 1e9+7;
int N, M;
int l[MAX_M], r[MAX_M], x[MAX_M];
ll dp[MAX_N+1][MAX_N+1][MAX_N+1];

bool judge(int i, int j, int m) {
  if (x[m] == 1) {
    return i < l[m] && j < l[m];
  } else if (x[m] == 2) {
    return (i < l[m] && j >= l[m]) || (i >= l[m] && j < l[m]);
  } else if (x[m] == 3) {
    return i >= l[m] && j >= l[m];
  }
  return false;
}

int main() {
  cin >> N >> M;
  rep(i,M) cin >> l[i] >> r[i] >> x[i];
  
  if (N == 1) {
    for (int i = 0; i < M; ++i) {
      if (x[i] > 1) {
        cout << 0 << endl;
        return 0;
      }
    }
  }

  dp[1][0][0] = dp[0][1][0] = dp[0][0][1] = 1;
  for (int k = 1; k < N; ++k) {
    // r[i] == k+1 を満たすiを列挙
    vector<int> vec;
    for (int i = 0; i < M; ++i) {
      if (r[i] == k+1) vec.push_back(i);
    }
    
    // r = k から更新
    for (int b = 0; b < k; ++b) {
      for (int g = 0; g < k; ++g) {

        // r = k+1
        bool ok = true;
        for (int i = 0; i < vec.size(); ++i) {
          ok &= judge(b, g, vec[i]);
        }
        if (ok) (dp[k+1][b][g] += dp[k][b][g]) %= MOD;
        
        // b = k+1
        ok = true;
        for (int i = 0; i < vec.size(); ++i) {
          ok &= judge(k, g, vec[i]);
        }
        if (ok) (dp[k][k+1][g] += dp[k][b][g]) %= MOD;

        // g = k+1
        ok = true;
        for (int i = 0; i < vec.size(); ++i) {
          ok &= judge(k, b, vec[i]);
        }
        if (ok) (dp[k][b][k+1] += dp[k][b][g]) %= MOD;
      }
    }

    // b = k から更新
    for (int r = 0; r < k; ++r) {
      for (int g = 0; g < k; ++g) {

        // r = k+1
        bool ok = true;
        for (int i = 0; i < vec.size(); ++i) {
          ok &= judge(k, g, vec[i]);
        }
        if (ok) (dp[k+1][k][g] += dp[r][k][g]) %= MOD;
        
        // b = k+1
        ok = true;
        for (int i = 0; i < vec.size(); ++i) {
          ok &= judge(r, g, vec[i]);
        }
        if (ok) (dp[r][k+1][g] += dp[r][k][g]) %= MOD;

        // g = k+1
        ok = true;
        for (int i = 0; i < vec.size(); ++i) {
          ok &= judge(r, k, vec[i]);
        }
        if (ok) (dp[r][k][k+1] += dp[r][k][g]) %= MOD;
      }
    }
    
    // g = k から更新
    for (int r = 0; r < k; ++r) {
      for (int b = 0; b < k; ++b) {

        // r = k+1
        bool ok = true;
        for (int i = 0; i < vec.size(); ++i) {
          ok &= judge(b, k, vec[i]);
        }
        if (ok) (dp[k+1][b][k] += dp[r][b][k]) %= MOD;
        
        // b = k+1
        ok = true;
        for (int i = 0; i < vec.size(); ++i) {
          ok &= judge(r, k, vec[i]);
        }
        if (ok) (dp[r][k+1][k] += dp[r][b][k]) %= MOD;

        // g = k+1
        ok = true;
        for (int i = 0; i < vec.size(); ++i) {
          ok &= judge(r, b, vec[i]);
        }
        if (ok) (dp[r][b][k+1] += dp[r][b][k]) %= MOD;
      }
    }
  }

  ll ans = 0;
  // r = N
  for (int b = 0; b < N; ++b) {
    for (int g = 0; g < N; ++g) {
      (ans += dp[N][b][g]) %= MOD;
    }
  }

  // b = N
  for (int r = 0; r < N; ++r) {
    for (int g = 0; g < N; ++g) {
      (ans += dp[r][N][g]) %= MOD;
    }
  }

  // g = N
  for (int r = 0; r < N; ++r) {
    for (int b = 0; b < N; ++b) {
      (ans += dp[r][b][N]) %= MOD;
    }
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 213248