#include<bits/stdc++.h>
using namespace std;

struct Query {int l, r, x;};

using I = long long;
const I MOD = 1e9 + 7;

I dp[301][301][301];

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<Query>> Q(N+1);
  for(auto i=0; i<M; ++i) {
    Query q;
    cin >> q.l >> q.r >> q.x;
    Q[q.r].emplace_back(q);
  }

  auto ok = [&](vector<int> v) {
    sort(begin(v), end(v));
    for(auto q: Q[v.back()]) {
      if(q.x==1) if(!(v[1]<q.l))               return false;
      if(q.x==2) if(!(v[0]<q.l && q.l<=v[1]))  return false;
      if(q.x==3) if(!(q.l<=v[0]))              return false;
    }
    return true;
  };

  dp[0][0][0] = 1;
  for(auto r=0; r<N; ++r) for(auto g=0; g<N; ++g) for(auto b=0; b<N; ++b) if(dp[r][g][b]) {
    if(!ok({r, g, b})) dp[r][g][b] = 0;
    auto k = max({r, g, b}) + 1;
    (dp[k][g][b] += dp[r][g][b]) %= MOD;
    (dp[r][k][b] += dp[r][g][b]) %= MOD;
    (dp[r][g][k] += dp[r][g][b]) %= MOD;
  }

  I res = 0;
  for(auto i=0; i<N; ++i) for(auto j=0; j<N; ++j) if(ok({N, i, j})) (res += dp[N][i][j] + dp[i][N][j] + dp[i][j][N]) %= MOD;
  cout << res << endl;
}
