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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

using P = pair<int, int>;
int n, m;
vector<vector<P>> memo;
vector<vector<vector<ModInt<>>>> dp;

ModInt<> solve();

int main() {
  cin >> n >> m;
  memo.resize(n + 1);
  for (int i = 0; i < m; ++i) {
    int l, r, x;
    cin >> l >> r >> x;
    memo[r].emplace_back(l, x);
  }
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  auto check = [](P &p, int now) { return p.first <= now && now < p.second; };
  dp.assign(n + 1, vector(n + 1, vector<ModInt<>>(n + 1, 0)));
  dp[0][0][0] = 1;
  for (int i = 0; i < n; ++i) {
    P jsec(0, i + 1), ksec(0, i + 1);
    for (auto p : memo[i + 1]) {
      if (p.second == 1) {
        jsec = P(max(jsec.first, 0), min(jsec.second, p.first));
        ksec = P(max(ksec.first, 0), min(ksec.second, p.first));
      } else if (p.second == 2) {
        jsec = P(max(jsec.first, p.first), min(jsec.second, i + 1));
        ksec = P(max(ksec.first, 0), min(ksec.second, p.first));
      } else {
        jsec = P(max(jsec.first, p.first), min(jsec.second, i + 1));
        ksec = P(max(ksec.first, p.first), min(ksec.second, i + 1));
      }
    }
    for (int j = 0; j <= i; ++j)
      for (int k = 0; k <= i; ++k) {
        if (check(jsec, j) && check(ksec, k)) dp[i + 1][j][k] += dp[i][j][k];
        if (check(jsec, i) && check(ksec, j)) dp[i + 1][i][j] += dp[i][j][k];
        if (check(jsec, i) && check(ksec, k)) dp[i + 1][i][k] += dp[i][j][k];
      }
  }
  ModInt<> res;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++j) res += dp[n][i][j];
  return res;
}

Measured memory_bytes: 113364