#include <bits/stdc++.h>
int head[262144], last[128], to[128], w[128], cnt = 0;
int id[262144], size[262144];
bool vis[262144], vis2[262144];
int jc[131072];
int dp2[200005][60], dp3[200005][60];
int tmp[131072];
void add(int u, int v, int ww) {
  cnt++;
  last[cnt] = head[u];
  head[u] = cnt;
  to[cnt] = v;
  w[cnt] = ww;
}
int n, k;
int numx, vx[131072], numy, vy[131072];
int fs, uu[131072], vv[131072], val[131072];
void dfs(int u, int f) {
  if (u <= n) {
    vx[numx] = u;
    id[u] = numx;
    numx++;
  } else {
    vy[numy] = u;
    id[u] = numy;
    numy++;
  }
  for (int i = head[u]; i; i = last[i]) {
    int v = to[i];
    if (v == f) {
      continue;
    }
    if (id[v] >= 0) {
      if (u <= n) {
        uu[fs] = u;
        vv[fs] = v;
        val[fs] = w[i];
        fs++;
      }
      continue;
    }
    dfs(v, u);
  }
}
void sol(int u) {
  size[u] = 1;
  vis[u] = true;
  dp2[u][0] = vis2[u];
  dp3[u][0] = !vis2[u];
  for (int x = head[u]; x; x = last[x]) {
    int v = to[x];
    if (vis[v]) {
      continue;
    }
    sol(v);
    for (int i = 0; i < ((size[u] + size[v]) << 1); i++) {
      tmp[i] = 0;
    }
    for (int i = 0; i < size[u]; i++) {
      for (int j = 0; j < size[v]; j++) {
        tmp[i + j] += (long long)dp3[u][i] * dp3[v][j] % 1000000007;
        if (tmp[i + j] >= 1000000007) {
          tmp[i + j] -= 1000000007;
        }
        tmp[i + j] += (long long)dp3[u][i] * dp2[v][j] % 1000000007;
        if (tmp[i + j] >= 1000000007) {
          tmp[i + j] -= 1000000007;
        }
        tmp[i + j + size[u] + size[v]] +=
            (long long)dp2[u][i] * dp3[v][j] % 1000000007;
        if (tmp[i + j + size[u] + size[v]] >= 1000000007) {
          tmp[i + j + size[u] + size[v]] -= 1000000007;
        }
        tmp[i + j + size[u] + size[v]] +=
            (long long)dp2[u][i] * dp2[v][j] % 1000000007;
        if (tmp[i + j + size[u] + size[v]] >= 1000000007) {
          tmp[i + j + size[u] + size[v]] -= 1000000007;
        }
        int t = (long long)dp3[u][i] * dp3[v][j] % 1000000007;
        t = (long long)t * w[x] % 1000000007;
        tmp[i + j + size[u] + size[v] + 1] += t;
        if (tmp[i + j + size[u] + size[v] + 1] >= 1000000007) {
          tmp[i + j + size[u] + size[v] + 1] -= 1000000007;
        }
      }
    }
    size[u] += size[v];
    for (int i = 0; i < size[u]; i++) {
      dp3[u][i] = tmp[i];
      dp2[u][i] = tmp[i + size[u]];
    }
  }
}
int ans[64], ans2[128];
int dp[131072];
int main() {
  scanf("%d%d", &n, &k);
  jc[0] = 1;
  for (int i = 1; i <= n; i++) {
    jc[i] = (long long)jc[i - 1] * i % 1000000007;
  }
  for (int i = 0; i < k; i++) {
    int x, y, ww;
    scanf("%d%d%d", &x, &y, &ww);
    ww--;
    if (ww < 0) {
      ww += 1000000007;
    }
    add(x, y + n, ww);
    add(y + n, x, ww);
  }
  if (k > n) {
    k = n;
  }
  for (int i = 1; i <= (n << 1); i++) {
    id[i] = -1;
  }
  ans[0] = 1;
  for (int u = 1; u <= (n << 1); u++) {
    if (id[u] >= 0) {
      continue;
    }
    numx = 0;
    numy = 0;
    fs = 0;
    dfs(u, 0);
    if (numx + numy <= 1) {
      continue;
    }
    if (fs <= numx && fs <= numy) {
      for (int i = 0; i <= k; i++) {
        ans2[i] = 0;
      }
      for (int i = 0; i < (1 << fs); i++) {
        for (int j = 0; j < numx; j++) {
          vis[vx[j]] = false;
          vis2[vx[j]] = false;
        }
        for (int j = 0; j < numy; j++) {
          vis[vy[j]] = false;
          vis2[vy[j]] = false;
        }
        int ww = 1;
        int cnt = 0;
        bool ok = true;
        for (int j = 0; j < fs; j++) {
          if (!(i & (1 << j))) {
            continue;
          }
          if (vis2[uu[j]]) {
            ok = false;
            break;
          }
          vis2[uu[j]] = true;
          if (vis2[vv[j]]) {
            ok = false;
            break;
          }
          vis2[vv[j]] = true;
          ww = (long long)ww * val[j] % 1000000007;
          cnt++;
        }
        if (!ok) {
          continue;
        }
        sol(u);
        for (int j = 0; j < size[u]; j++) {
          ans2[j + cnt] += (long long)(dp2[u][j] + dp3[u][j]) * ww % 1000000007;
          if (ans2[j + cnt] >= 1000000007) {
            ans2[j + cnt] -= 1000000007;
          }
        }
      }
      for (int i = 0; i <= k; i++) {
        tmp[i] = 0;
      }
      for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
          tmp[i + j] += (long long)ans[i] * ans2[j] % 1000000007;
          if (tmp[i + j] >= 1000000007) {
            tmp[i + j] -= 1000000007;
          }
        }
      }
      for (int i = 0; i <= k; i++) {
        ans[i] = tmp[i];
      }
      continue;
    }
    if (numx <= numy) {
      for (int i = 0; i < numy; i++) {
        int t = vx[i];
        vx[i] = vy[i];
        vy[i] = t;
      }
      int t = numx;
      numx = numy;
      numy = t;
    }
    for (int i = 0; i < (1 << numy); i++) {
      dp[i] = 0;
    }
    dp[0] = 1;
    for (int i = 0; i < numx; i++) {
      for (int j = 0; j < (1 << numy); j++) {
        tmp[j] = dp[j];
      }
      for (int j = head[vx[i]]; j; j = last[j]) {
        int v = id[to[j]];
        for (int k = 0; k < (1 << numy); k++) {
          if (k & (1 << v)) {
            continue;
          }
          dp[k ^ (1 << v)] += (long long)tmp[k] * w[j] % 1000000007;
          if (dp[k ^ (1 << v)] >= 1000000007) {
            dp[k ^ (1 << v)] -= 1000000007;
          }
        }
      }
    }
    for (int i = 0; i <= k; i++) {
      tmp[i] = 0;
    }
    for (int i = 0; i < (1 << numy); i++) {
      int cnt = 0;
      for (int j = 0; j < numy; j++) {
        if (i & (1 << j)) {
          cnt++;
        }
      }
      for (int j = 0; j <= k; j++) {
        tmp[j + cnt] += (long long)ans[j] * dp[i] % 1000000007;
        if (tmp[j + cnt] >= 1000000007) {
          tmp[j + cnt] -= 1000000007;
        }
      }
    }
    for (int i = 0; i <= k; i++) {
      ans[i] = tmp[i];
    }
  }
  int answer = 0;
  for (int i = 0; i <= k; i++) {
    answer += (long long)ans[i] * jc[n - i] % 1000000007;
    if (answer >= 1000000007) {
      answer -= 1000000007;
    }
  }
  printf("%d\n", answer);
  return 0;
}
