#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50, mo = 1e9 + 7;
int gi() {
  char ch = getchar();
  int x = 0, q = 0;
  while (ch < '0' || ch > '9') q = ch == '-' ? 1 : q, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return q ? -x : x;
}
struct data {
  int x, y, z;
  bool operator<(const data &c) const {
    if (x != c.x) return x < c.x;
    return y < c.y;
  }
} w[55];
int fap(int a, int b) {
  int s = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mo)
    if (b & 1) s = 1ll * s * a % mo;
  return s;
}
int tt, m, pl[N], a[N], b[N], c[N], val[200], st[N];
namespace dp {
int f[200][55], g[200][55], vis[200], sz[200], head[200], nn[N][3],
    sum = 1, cnt, w[200], num;
void clr() {
  memset(val, 0, sizeof(val));
  memset(head, 0, sizeof(head));
  cnt = 0;
  return;
}
void lnk(int x, int y, int z) {
  nn[++cnt][1] = y, nn[cnt][0] = head[x], head[x] = cnt, nn[cnt][2] = z;
  nn[++cnt][1] = x, nn[cnt][0] = head[y], head[y] = cnt, nn[cnt][2] = z;
  return;
}
void dfs(int x, int fa) {
  sz[x] = vis[x] ^ 1;
  for (int i = 0; i <= m; ++i) f[x][i] = g[x][i] = 0;
  g[x][0] = 1;
  for (int i = head[x], y; i; i = nn[i][0])
    if ((y = nn[i][1]) != fa) {
      dfs(y, x);
      int l = sz[x] / 2, r = sz[y] / 2, q = nn[i][2];
      for (int j = l; ~j; --j) w[j] = f[x][j], f[x][j] = 0;
      for (int j = 0; j <= l; ++j)
        for (int k = 0; k <= r; ++k)
          ((f[x][j + k] += 1ll * w[j] * f[y][k] % mo) %= mo);
      for (int j = l; ~j; --j) w[j] = g[x][j], g[x][j] = 0;
      for (int j = 0; j <= l; ++j)
        for (int k = 0; k <= r; ++k) {
          ((g[x][j + k] += 1ll * w[j] * f[y][k] % mo) %= mo);
          if (!vis[y])
            ((f[x][j + k + 1] += 1ll * q * w[j] % mo * g[y][k] % mo) %= mo);
        }
      sz[x] += sz[y];
    }
  if (vis[x])
    for (int i = sz[x] / 2; ~i; --i) f[x][i] = 0;
  for (int i = sz[x] / 2; ~i; --i) ((f[x][i] += g[x][i]) %= mo);
  return;
}
void solve(int t) {
  if (t > tt) {
    dfs(1, 0);
    for (int i = m / 2 - num; ~i; --i)
      ((val[i + num] += 1ll * sum * f[1][i] % mo) %= mo);
    return;
  }
  int cs = sum;
  if (!vis[a[t]] && !vis[b[t]]) {
    sum = 1ll * sum * c[t] % mo, vis[a[t]] = vis[b[t]] = 1;
    ++num, solve(t + 1), --num;
    sum = cs, vis[a[t]] = vis[b[t]] = 0;
  }
  solve(t + 1);
  return;
}
}  // namespace dp
int n, k, S, p[N], head[N], vis[N], nn[N][3], cnt, g[N], siz[N], top, tot;
int f[2][1 << 16], fa[N];
void dfs(int x) {
  vis[x] = 0, st[++tot] = x;
  for (int i = head[x], y; i; i = nn[i][0])
    if (vis[y = nn[i][1]]) dfs(y);
  return;
}
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
  cin >> n >> k, pl[0] = g[0] = 1;
  for (int i = 1; i <= n; ++i) pl[i] = 1ll * pl[i - 1] * i % mo;
  int x, y, z;
  for (int i = 1; i <= k; ++i) {
    x = gi(), y = gi(), z = gi() - 1, vis[x] = vis[y + n] = 1;
    (nn[++cnt][1] = y + n, nn[cnt][0] = head[x], head[x] = cnt, nn[cnt][2] = z),
        (nn[++cnt][1] = x, nn[cnt][0] = head[y + n], head[y + n] = cnt,
         nn[cnt][2] = z);
  }
  for (int i = 1; i < (1 << 16); ++i) siz[i] = siz[i >> 1] + (i & 1);
  int num = 0;
  for (int u = 1; u <= n; ++u)
    if (vis[u]) {
      m = tot = 0, dfs(u);
      sort(st + 1, st + tot + 1);
      while (st[tot] > n) p[st[tot--]] = m++;
      if (m <= 0) {
        S = 1 << m;
        for (int i = 0; i < S; ++i) f[0][i] = 0;
        f[0][0] = 1;
        int t = 0;
        for (int i = 1; i <= tot; ++i) {
          top = 0;
          for (int j = head[st[i]]; j; j = nn[j][0])
            a[++top] = p[nn[j][1]], b[top] = nn[j][2];
          t ^= 1;
          for (int j = 0; j < S; ++j) f[t][j] = 0;
          for (int s = 0, v; s < S; ++s)
            if (f[t ^ 1][s]) {
              for (int j = 1; j <= top; ++j)
                if (!(s >> (v = a[j]) & 1))
                  ((f[t][s | 1 << v] += 1ll * f[t ^ 1][s] * b[j] % mo) %= mo);
              ((f[t][s] += f[t ^ 1][s]) %= mo);
            }
        }
        for (int i = 0; i <= m; ++i) a[i] = 0;
        for (int i = 0; i < S; ++i) ((a[siz[i]] += f[t][i]) %= mo);
        for (int i = 0; i <= num; ++i) b[i] = g[i], g[i] = 0;
        for (int i = 0; i <= num; ++i)
          for (int j = 0; j <= m; ++j)
            ((g[i + j] += 1ll * b[i] * a[j] % mo) %= mo);
      } else {
        m += tot, tt = 0;
        for (int i = 1; i <= m; ++i) p[st[i]] = fa[i] = i;
        for (int i = 1; i <= tot; ++i)
          for (int j = head[st[i]]; j; j = nn[j][0]) {
            y = p[nn[j][1]];
            if (find(i) == find(y))
              a[++tt] = i, b[tt] = y, c[tt] = nn[j][2];
            else
              fa[fa[i]] = fa[y], dp::lnk(i, y, nn[j][2]);
          }
        dp::solve(1);
        m -= tot;
        for (int i = 0; i <= m; ++i) a[i] = val[i];
        for (int i = 0; i <= num; ++i) b[i] = g[i], g[i] = 0;
        for (int i = 0; i <= num; ++i)
          for (int j = 0; j <= m; ++j)
            ((g[i + j] += 1ll * b[i] * a[j] % mo) %= mo);
      }
      num += m, dp::clr();
    }
  int ans = 0;
  for (int i = 0; i <= num; ++i) ((ans += 1ll * g[i] * pl[n - i] % mo) %= mo);
  cout << ans;
  return 0;
}
