#include <bits/stdc++.h>
using namespace std;
const int Maxk = 125;
const int Maxn = 2E5 + 5;
const int Mod = 1E9 + 7;
int N, K;
struct NO {
  int x, y, w;
} a[Maxk];
int nx, ny;
int Px[Maxn], Py[Maxn];
int Dx[Maxn], Dy[Maxn];
long long mxk[Maxk];
int W[Maxk][Maxk];
vector<int> V[Maxk];
unordered_map<long long, int> f[Maxk][Maxk];
unordered_map<long long, int>::iterator it;
int Ans;
int fac[Maxn];
void init() {
  fac[0] = 1;
  for (int i = 1; i <= N; ++i)
    Px[i] = Py[i] = i, fac[i] = (long long)fac[i - 1] * i % Mod;
  random_shuffle(Px + 1, Px + N + 1), random_shuffle(Py + 1, Py + N + 1);
  for (int i = 1; i <= K; ++i) {
    scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].w);
    a[i].x = Px[a[i].x], a[i].y = Py[a[i].y], --a[i].w;
    Dx[++nx] = a[i].x, Dy[++ny] = a[i].y;
  }
  sort(Dx + 1, Dx + nx + 1), sort(Dy + 1, Dy + ny + 1);
  nx = unique(Dx + 1, Dx + nx + 1) - (Dx + 1);
  ny = unique(Dy + 1, Dy + ny + 1) - (Dy + 1);
  for (int i = 1; i <= K; ++i) {
    a[i].x = lower_bound(Dx + 1, Dx + nx + 1, a[i].x) - Dx;
    a[i].y = lower_bound(Dy + 1, Dy + ny + 1, a[i].y) - Dy;
    W[a[i].x][a[i].y] = a[i].w, V[a[i].x].push_back(a[i].y);
  }
  mxk[nx + 1] = 0;
  for (int i = nx; i >= 1; --i) {
    mxk[i] = mxk[i + 1];
    for (int j = 0; j < V[i].size(); ++j) mxk[i] |= 1ll << V[i][j];
  }
}
void Work() {
  f[0][0][0] = 1;
  for (int i = 1; i <= nx; ++i) {
    int sz = V[i].size();
    for (int j = 0; j <= i; ++j) {
      for (it = f[i - 1][j].begin(); it != f[i - 1][j].end(); ++it) {
        long long t = (it->first) & mxk[i];
        f[i][j][t] += it->second;
        if (f[i][j][t] >= Mod) f[i][j][t] -= Mod;
      }
      if (!j) continue;
      for (it = f[i - 1][j - 1].begin(); it != f[i - 1][j - 1].end(); ++it)
        for (int k = 0; k < sz; ++k) {
          if (((it->first) >> V[i][k]) & 1) continue;
          long long t = ((it->first) | (1ll << V[i][k])) & mxk[i];
          f[i][j][t] =
              (f[i][j][t] + (long long)(it->second) * W[i][V[i][k]]) % Mod;
        }
    }
  }
  Ans = 0;
  for (int j = 0; j <= nx; ++j)
    for (it = f[nx][j].begin(); it != f[nx][j].end(); ++it)
      Ans = (Ans + (long long)fac[N - j] * (it->second)) % Mod;
  printf("%d\n", Ans);
}
int main() {
  srand(20011006);
  scanf("%d %d", &N, &K);
  init(), Work();
  return 0;
}
