import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=rdsp;foreach(ref j;v.tupleof)pick(r,j);}}

const mod = 10^^9+7;
alias mint = FactorRing!mod;

void main()
{
  int n, m; readV(n, m);
  struct C { int l, r, x; }
  C[] c; readS(m, c);

  C[][int] ch;
  foreach (ci; c) ch[ci.r] ~= ci;

  auto dp = new int[][][](n+1, n+1, n+1);
  dp[0][0][0] = 1;

  foreach (r; 0..n+1)
    foreach (g; 0..n+1)
      foreach (b; 0..n+1) {
        auto k = max(r, g, b);

        if (k in ch) {
          foreach (ci; ch[k]) {
            if (r == k) {
              if ((b >= ci.l) + (g >= ci.l) + 1 != ci.x)
                dp[r][g][b] = 0;
            } else if (g == k) {
              if ((r >= ci.l) + (b >= ci.l) + 1 != ci.x)
                dp[r][g][b] = 0;
            } else {
              if ((r >= ci.l) + (g >= ci.l) + 1 != ci.x)
                dp[r][g][b] = 0;
            }
          }
        }

        if (k < n) {
          (dp[k+1][g][b] += dp[r][g][b]) %= mod;
          (dp[r][k+1][b] += dp[r][g][b]) %= mod;
          (dp[r][g][k+1] += dp[r][g][b]) %= mod;
        }
      }

  auto ans = 0;
  foreach (c1; 0..n)
    foreach (c2; 0..n) {
      (ans += dp[n][c1][c2]) %= mod;
      (ans += dp[c1][n][c2]) %= mod;
      (ans += dp[c1][c2][n]) %= mod;
    }

  writeln(ans);
}

struct FactorRing(int m, bool pos = false)
{
  version(BigEndian) union { long vl; struct { int vi2; int vi; } } else union { long vl; int vi; }
  alias FR = FactorRing!(m, pos);
  @property static init() { return FR(0); }
  @property int value() { return vi; }
  @property void value(int v) { vi = mod(v); }
  alias value this;

  this(int v) { vi = v; }
  this(int v, bool runMod) { vi = runMod ? mod(v) : v; }
  this(long v) { vi = mod(v); }

  ref auto opAssign(int v) { vi = v; return this; }

  pure auto mod(int v) const { static if (pos) return v%m; else return (v%m+m)%m; }
  pure auto mod(long v) const { static if (pos) return cast(int)(v%m); else return cast(int)((v%m+m)%m); }

  static if (!pos) pure ref auto opUnary(string op: "-")() { return FR(mod(-vi)); }

  static if (m < int.max / 2) {
    pure ref auto opBinary(string op)(int r) if (op == "+" || op == "-") { return FR(mod(mixin("vi"~op~"r"))); }
    ref auto opOpAssign(string op)(int r) if (op == "+" || op == "-") { vi = mod(mixin("vi"~op~"r")); return this; }
  } else {
    pure ref auto opBinary(string op)(int r) if (op == "+" || op == "-") { return FR(mod(mixin("vl"~op~"r"))); }
    ref auto opOpAssign(string op)(int r) if (op == "+" || op == "-") { vi = mod(mixin("vl"~op~"r")); return this; }
  }
  pure ref auto opBinary(string op: "*")(int r) { return FR(mod(vl*r)); }
  ref auto opOpAssign(string op: "*")(int r) { vi = mod(vl*r); return this; }

  pure ref auto opBinary(string op)(ref FR r) if (op == "+" || op == "-" || op == "*") { return opBinary!op(r.vi); }
  ref auto opOpAssign(string op)(ref FR r) if (op == "+" || op == "-" || op == "*") { return opOpAssign!op(r.vi); }
}


Measured memory_bytes: 192892