#include <bits/stdc++.h>
using namespace std;
inline int M(int x) { return (x >= 1000000007) ? (x - 1000000007) : x; }
inline void Add(int &x, int v) { x = M(x + v); }
inline int M1(int x) { return (x < 0) ? (x + 1000000007) : x; }
inline int ksm(int p, int k) {
  int res = 1;
  while (k) {
    if (k & 1) res = 1ll * res * p % 1000000007;
    k >>= 1;
    p = 1ll * p * p % 1000000007;
  }
  return res;
}
int fac[100012], ans = 0;
int n, m, c1[100012], c2[100012], X[100012], Y[100012], V[100012], rev[100012],
    tot = 0, tou, rem, son[27], so[27], t1, t2;
struct Po {
  int y, v;
} a[27][52], b[27][52];
int t = 0;
bool vis[100012];
int f[52], g[52];
unsigned long long al = 0;
map<unsigned long long, int[20]> q;
map<unsigned long long, int[20]>::iterator it, it1;
void dfs(int x, int v, unsigned long long S) {
  if (x > tou) {
    it = q.find((~S) & al);
    for (int i = 0; i <= rem; i++)
      g[t + i] = (g[t + i] + 1ll * v * ((it->second)[i])) % 1000000007;
    return;
  }
  dfs(x + 1, v, S);
  int i;
  Po p;
  for (i = 1; i <= son[x]; i++)
    if (!vis[(p = a[x][i]).y])
      vis[p.y] = 1, ++t,
      dfs(x + 1, 1ll * v * p.v % 1000000007, S | (1ull << p.y)), vis[p.y] = 0,
      --t;
}
void dfs2(int x, int v, unsigned long long S) {
  if (x > tot) {
    al |= S;
    Add(q[S][t], v);
    return;
  }
  dfs2(x + 1, v, S);
  int i;
  Po p;
  for (i = 1; i <= son[x]; i++)
    if (!vis[(p = a[x][i]).y])
      vis[p.y] = 1, ++t,
      dfs2(x + 1, 1ll * v * p.v % 1000000007, S | (1ull << p.y)), vis[p.y] = 0,
      --t;
}
vector<int> ves;
bool hv[52];
void dfs1(int x) {
  ves.push_back(x);
  hv[x] = 1;
  for (int y = 1; y <= m; y++)
    if ((!hv[y]) && ((X[x] == X[y]) || (Y[x] == Y[y]))) dfs1(y);
}
int w[100012], cn = 0, re[52];
inline bool cmp(int x, int y) { return so[x] > so[y]; }
void solve() {
  for (auto o : ves) ++c1[X[o]], ++c2[Y[o]];
  t1 = t2 = 0;
  int i, j, x, y, v, p;
  unsigned long long S;
  for (i = 1; i <= n; i++) t1 += (c1[i] > 0), t2 += (c2[i] > 0);
  for (auto o : ves) c1[X[o]] = c2[Y[o]] = 0;
  if (t2 < t1)
    for (auto o : ves) swap(X[o], Y[o]);
  for (auto o : ves) w[++cn] = Y[o];
  sort(w + 1, w + cn + 1);
  cn = unique(w + 1, w + cn + 1) - w - 1;
  for (auto o : ves) Y[o] = lower_bound(w + 1, w + cn + 1, Y[o]) - w - 1;
  for (auto o : ves) {
    x = X[o];
    y = Y[o];
    v = V[o];
    p = rev[x] ? rev[x] : (rev[x] = ++tot);
    b[p][++so[p]] = (Po){y, M1(v - 1)};
  }
  for (i = 1; i <= tot; i++) re[i] = i;
  sort(re + 1, re + tot + 1, cmp);
  for (i = 1; i <= tot; i++)
    memcpy(a[i], b[re[i]], sizeof(a[i])), son[i] = so[re[i]];
  for (i = 1; i <= tot; i++) so[i] = 0;
  tou = min(tot, 9);
  rem = tot - tou;
  al = 0;
  q.clear();
  dfs2(tou + 1, 1, 0);
  for (S = al; S; S = (S - 1) & al)
    if (!q.count(S)) q[S][0] = 0;
  for (i = 0; i < cn; i++)
    if (al & (1ull << i))
      for (S = al; S; S = (S - 1) & al)
        if (S & (1ull << i)) {
          it = q.find(S);
          it1 = q.find(S ^ (1ull << i));
          for (j = 0; j <= rem; j++) Add((it->second)[j], (it1->second)[j]);
        }
  dfs(1, 1, 0);
  for (auto o : ves) rev[X[o]] = 0;
  for (i = m; i >= 0; i--)
    for (j = 1; j <= min(i, tot); j++)
      f[i] = (f[i] + 1ll * f[i - j] * g[j]) % 1000000007;
  for (i = 0; i <= tot; i++) g[i] = 0;
  ves.clear();
  for (i = 1; i <= tot; i++) son[i] = 0;
  tot = 0;
  cn = 0;
}
int main() {
  fac[0] = 1;
  for (int i = 1; i < 100012; i++) fac[i] = 1ll * fac[i - 1] * i % 1000000007;
  f[0] = 1;
  scanf("%d%d", &n, &m);
  int i, x, y, v;
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &v);
    X[i] = x;
    Y[i] = y;
    V[i] = v;
  }
  for (i = 1; i <= m; i++)
    if (!hv[i]) dfs1(i), solve();
  for (i = 0; i <= m; i++) ans = (ans + 1ll * fac[n - i] * f[i]) % 1000000007;
  printf("%d", ans);
  return 0;
}
