#include <bits/stdc++.h>
using namespace std;
struct Tedge {
  int u, v, pre, w;
} edge[55 * 2], e[55];
int n, k, en = 1, cur[100010], tot, cnt[55], id[55][55], vste[55 * 2],
          vstp[100010][2], f[55][55], g[55][55], bitcnt[1 << 18];
int fac[100010], out[100010];
namespace force {
int a[100][100], arr[100], b[100];
long long ans;
void calc() {
  long long sum = 1;
  for (int i = 1; i <= n; i++) sum = sum * a[i][arr[i]] % 1000000007;
  ans = (ans + sum) % 1000000007;
}
void dfs(int p) {
  if (p == n + 1) return calc();
  for (int i = 1; i <= n; i++)
    if (!b[i]) {
      b[i] = 1;
      arr[p] = i;
      dfs(p + 1);
      b[i] = 0;
    }
}
void solve() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = 1;
  for (int i = 1; i <= k; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    a[x][y] = w;
  }
  ans = 0;
  dfs(1);
  printf("%I64d\n", ans);
}
}  // namespace force
void addedge(int u, int v, int w) {
  edge[++en] = (Tedge){u, v, cur[u], w}, cur[u] = en;
  edge[++en] = (Tedge){v, u, cur[v], w}, cur[v] = en;
}
void inc(int &a, int b) {
  if ((a += b) >= 1000000007) a -= 1000000007;
}
void dec(int &a, int b) {
  if ((a -= b) < 0) a += 1000000007;
}
void dfs(int p, int now, int typ, int &sl, int &sr) {
  if (!vstp[p][typ]) !typ ? sl++ : sr++;
  vstp[p][typ] = 1;
  for (int i = cur[p], v = edge[i].v; i; i = edge[i].pre, v = edge[i].v)
    if ((i & 1) == typ && !vste[i]) {
      id[now][++cnt[now]] = i ^ (i & 1);
      vste[i] = vste[i ^ 1] = 1;
      dfs(v, now, !typ, sl, sr);
    }
}
namespace dp1 {
int f[55][1 << 18], srt[55];
bool cmp(Tedge a, Tedge b) {
  if (a.u != b.u) return a.u < b.u;
  return a.v < b.v;
}
void init(Tedge e[], int n) {
  if (n >= 55) puts("???4");
  int t;
  for (int i = 1; i <= n; i++) srt[i] = e[i].u;
  sort(srt + 1, srt + 1 + n);
  t = unique(srt + 1, srt + 1 + n) - (srt + 1);
  for (int i = 1; i <= n; i++)
    e[i].u = lower_bound(srt + 1, srt + 1 + t, e[i].u) - (srt + 1) + 1;
  for (int i = 1; i <= n; i++) srt[i] = e[i].v;
  sort(srt + 1, srt + 1 + n);
  t = unique(srt + 1, srt + 1 + n) - (srt + 1);
  for (int i = 1; i <= n; i++)
    e[i].v = lower_bound(srt + 1, srt + 1 + t, e[i].v) - (srt + 1) + 1;
  sort(e + 1, e + 1 + n, cmp);
}
int get(int s, int p) { return (s >> (p - 1)) & 1; }
int set(int s, int p, int x) { return (s ^ get(s, p)) ^ (x << (p - 1)); }
void solve(int n, int m, int en, Tedge e[], int res[]) {
  if (n < m) puts("??5");
  init(e, en);
  int s = (1 << m) - 1, now = 1;
  memset(f, 0, sizeof(f));
  f[0][0] = 1;
  for (int i = 0; i <= n - 1; i++) {
    for (int j = 0; j <= s; j++) {
      inc(f[i + 1][j], f[i][j]);
      for (int p = now; p <= en && e[p].u == i + 1; p++)
        if (f[i][j] && get(j, e[p].v) == 0)
          inc(f[i + 1][set(j, e[p].v, 1)],
              1LL * f[i][j] * (e[p].w - 1) % 1000000007);
    }
    for (; now <= en && e[now].u == i + 1; now++)
      ;
  }
  for (int i = 0; i <= s; i++) inc(res[bitcnt[i]], f[n][i]);
  if ((s && !bitcnt[s]) || bitcnt[s] > 18) puts("??3");
}
}  // namespace dp1
namespace dp2 {
Tedge edge[55 * 2], *e;
int n, en, cur[55], typ[55 * 2], vst[55], a[55], an, b[55], *ans, f[55][55][2],
    srt[55], siz[55];
void addedge(int u, int v, int w) {
  edge[++en] = (Tedge){u, v, cur[u], w}, cur[u] = en;
  edge[++en] = (Tedge){v, u, cur[v], w}, cur[v] = en;
}
void clear() { en = 1, memset(cur, 0, sizeof(cur)); }
void init(Tedge e[], int n) {
  int t1, t2;
  for (int i = 1; i <= n; i++) srt[i] = e[i].u;
  sort(srt + 1, srt + 1 + n);
  t1 = unique(srt + 1, srt + 1 + n) - (srt + 1);
  for (int i = 1; i <= n; i++)
    e[i].u = lower_bound(srt + 1, srt + 1 + t1, e[i].u) - (srt + 1) + 1;
  for (int i = 1; i <= n; i++) srt[i] = e[i].v;
  sort(srt + 1, srt + 1 + n);
  t2 = unique(srt + 1, srt + 1 + n) - (srt + 1);
  for (int i = 1; i <= n; i++)
    e[i].v = lower_bound(srt + 1, srt + 1 + t2, e[i].v) - (srt + 1) + 1 + t1;
}
void gettr(int p) {
  vst[p] = 1;
  for (int i = cur[p], v = edge[i].v; i; i = edge[i].pre, v = edge[i].v)
    if (!vst[v]) {
      typ[i] = typ[i ^ 1] = 1;
      gettr(v);
    }
}
void dfs(int p, int fa, int fr) {
  f[p][1][1] = 1;
  int h[55];
  memset(h, 0, sizeof(h));
  h[0] = 1;
  siz[p] = 1;
  for (int i = cur[p], v = edge[i].v; i; i = edge[i].pre, v = edge[i].v)
    if (v != fa && typ[i]) {
      dfs(v, p, i);
      siz[p] += siz[v];
      for (int j = siz[p]; j >= 1; j--) {
        f[p][0][0] = 1;
        for (int k = 1; k <= j; k++) {
          inc(f[p][j][0], 1LL * f[v][k][0] * f[p][j - k][0] % 1000000007);
          inc(f[p][j][0], 1LL * f[v][k][1] * h[j - k] % 1000000007);
          inc(f[p][j][1], 1LL * f[v][k][0] * f[p][j - k][1] % 1000000007);
        }
        f[p][0][0] = 0;
      }
      for (int j = siz[p]; j >= 1; j--)
        for (int k = 1; k <= j; k++)
          inc(h[j], 1LL * h[j - k] * f[v][k][0] % 1000000007);
    }
  for (int i = 1; i <= n; i++)
    f[p][i][1] = 1LL * f[p][i][1] * (edge[fr].w - 1) % 1000000007;
  if (vst[p] || vst[fa])
    for (int i = 0; i <= siz[p]; i++) f[p][i][1] = 0;
}
void calc() {
  memset(vst, 0, sizeof(vst));
  int cnt = 0, sum = 1;
  for (int i = 1; i <= an; i++)
    if (b[i]) {
      if (vst[e[a[i]].u] || vst[e[a[i]].v]) return;
      vst[e[a[i]].u] = vst[e[a[i]].v] = 1;
      cnt++, sum = 1LL * sum * (e[a[i]].w - 1) % 1000000007;
    }
  memset(f, 0, sizeof(f));
  dfs(1, 0, 0);
  f[1][0][0] = 1;
  for (int i = 0; i <= n; i++)
    inc(ans[cnt + i], 1LL * f[1][i][0] * sum % 1000000007);
}
void dfs(int p) {
  if (p == an + 1) return calc();
  for (int i = 0; i <= 1; i++) b[p] = i, dfs(p + 1);
}
void solve(int _n, int en, Tedge _e[], int res[]) {
  if (_n >= 55) puts("???7");
  n = _n, e = _e, ans = res;
  init(e, en);
  clear();
  for (int i = 1; i <= en; i++) addedge(e[i].u, e[i].v, e[i].w);
  memset(vst, 0, sizeof(vst)), memset(typ, 0, sizeof(typ));
  gettr(1);
  an = 0;
  for (int i = 1; i <= en; i++)
    if (!typ[i << 1]) a[++an] = i;
  dfs(1);
}
}  // namespace dp2
void solve() {
  en = 1, memset(cur, 0, sizeof(cur)), memset(out, 0, sizeof(out));
  for (int i = 1; i <= k; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    out[u]++;
  }
  for (int i = 1; i <= (1 << 18) - 1; i++)
    bitcnt[i] = bitcnt[i - ((i) & (-(i)))] + 1;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % 1000000007;
  memset(f, 0, sizeof(f)), memset(cnt, 0, sizeof(cnt)),
      memset(vstp, 0, sizeof(vstp)), memset(vste, 0, sizeof(vste));
  tot = 0;
  for (int i = 1; i <= n; i++)
    if (out[i]) {
      int sl = 0, sr = 0;
      dfs(i, ++tot, 0, sl, sr);
      if (sl + sr > 55 * 2) puts("?1");
      if (cnt[tot] > 55) puts("?2");
      if (min(sl, sr) < 18) {
        if (sr < sl) {
          for (int j = 1; j <= cnt[tot]; j++) e[j] = edge[id[tot][j]];
          dp1::solve(sl, sr, cnt[tot], e, f[tot]);
        } else {
          for (int j = 1; j <= cnt[tot]; j++) e[j] = edge[id[tot][j] ^= 1];
          dp1::solve(sr, sl, cnt[tot], e, f[tot]);
        }
      } else {
        for (int j = 1; j <= cnt[tot]; j++) e[j] = edge[id[tot][j]];
        dp2::solve(sl + sr, cnt[tot], e, f[tot]);
      }
    }
  memset(g, 0, sizeof(g));
  g[0][0] = 1;
  for (int i = 1; i <= tot; i++)
    for (int j = 0; j <= k; j++) {
      g[i][j] = g[i - 1][j];
      for (int t = 1; t <= min(j, cnt[i]); t++)
        inc(g[i][j], 1LL * g[i - 1][j - t] * f[i][t] % 1000000007);
    }
  int ans = 0;
  for (int i = 0; i <= k; i++)
    inc(ans, 1LL * fac[n - i] * g[tot][i] % 1000000007);
  printf("%d\n", ans);
}
int main() {
  {
    scanf("%d%d", &n, &k);
    solve();
  }
  return 0;
}
