#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

mint dp[303][303][303];

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  vector<pair<P, int>> vec(m);
  rep(i, m) {
    int l, r, x; cin >> l >> r >> x;
    vec[i].first = P(r, l);
    vec[i].second = x;
    if (x > r-l+1) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(vec.begin(), vec.end());

  int now = 0;
  dp[0][0][0] = 1;

  for(int i=0; i<n; i++) {
    vector<int> lim(n, -1);
    vector<int> mi(4, INT_MAX), ma(4, INT_MIN);
    vector<bool> exist(4);
    while(now<m && vec[now].first.first==i+1) {
      int l = vec[now].first.second;
      int x = vec[now].second;
      // l=r, x=1 is no-op
      if (l != i+1) {
        chmin(mi[x],l); chmax(ma[x],l);
        exist[x] = true;
      }
      now++;
    }
    if (ma[3] >= mi[2] || ma[2] >= mi[1] || ma[3] >= mi[1]) {
      cout << 0 << endl;
      return 0;
    }
    vector<int> mi2(4), ma2(4);
    ma2[1] = i+1;
    mi2[1] = max(max(ma[2]+1, ma[3]+2), 1);
    ma2[2] = min(i, mi[1]-1);
    mi2[2] = max(ma[3]+1, 1);
    ma2[3] = min(min(i-1, mi[1]-2), mi[2]-1);
    mi2[3] = 1;
    debug(i, mi2[3], ma2[3], mi2[2], ma2[2], mi2[1], ma2[1]);

    // k==0 && j==0
    if (!exist[3]) {
      if (!exist[2]) dp[i+1][0][0] += dp[i][0][0];
      if (!exist[1]) dp[i+1][i][0] += dp[i][0][0]*2LL;
    }

    for(int j=0; j<i; j++) {
      for(int k=0; k<j; k++) {
        if (k <= ma2[3] && mi2[2] <= k+1 && j <= ma2[2] && mi2[1] <= j+1) {
          dp[i+1][j][k] += dp[i][j][k];
        }
        if (k <= ma2[3] && mi2[2] <= k+1 && i <= ma2[2] && mi2[1] <= i+1) {
          dp[i+1][i][k] += dp[i][j][k];
        }
        if (j <= ma2[3] && mi2[2] <= j+1 && i <= ma2[2] && mi2[1] <= i+1) {
          dp[i+1][i][j] += dp[i][j][k];
        }
      }
    }
    /**
    for(int j=0; j<=i; j++) {
      for(int k=0; k<=j; k++) {
        if (i<4) debug(i+1, j, k, dp[i+1][j][k].x);
      }
    }*/
  }
  mint ans = 0;
  for(int j=0; j<n; j++) {
    for(int k=0; k<j; k++) {
      ans += dp[n][j][k];
    }
  }
  ans += dp[n][0][0];
  cout << ans << endl;
}

Measured memory_bytes: 217728