#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int N = 55, Q = 105, M = 1 << 25, mod = 1000000007;
void up(int &x, int y) { x += y - mod, x += x >> 31 & mod; }
void up(int &x, int y, int z) { x = (x + (long long)y * z) % mod; }
int n, k, x[N], y[N], w[N], v[Q], tot;
int dp[2][M];
std::vector<std::pair<int, int>> e[Q], E[Q];
std::vector<int> left, right;
int id[Q];
bool vis[Q];
void dfs(int x) {
  vis[x] = 1;
  (v[x] <= n ? left : right).emplace_back(x);
  for (auto p : e[x])
    if (!vis[p.first]) dfs(p.first);
}
int ret[N], prod[N], tmp[N];
void solve() {
  if (left.size() > right.size()) std::swap(left, right);
  int n = left.size(), m = right.size();
  for (int i = 0; i < n; ++i) id[left[i]] = i;
  for (int i = 0; i < m; ++i) id[right[i]] = i;
  for (int i = 0; i < m; ++i)
    for (auto j : e[right[i]]) E[i].emplace_back(id[j.first], j.second);
  int now = 0, lst = 1;
  std::memset(dp[0], 0, 1 << n + 2);
  dp[0][0] = 1;
  int all = 0;
  for (int i = 0; i < m; ++i) {
    std::swap(now, lst), std::memcpy(dp[now], dp[lst], 1 << n + 2);
    for (auto e : E[i]) {
      int mask = all ^ 1 << e.first;
      all |= 1 << e.first;
      for (int j = mask;; j = j - 1 & mask) {
        up(dp[now][j | 1 << e.first], dp[lst][j], e.second);
        if (!j) break;
      }
    }
  }
  std::memset(ret, 0, sizeof ret);
  for (int i = 0; i < 1 << n; ++i) up(ret[__builtin_popcount(i)], dp[now][i]);
}
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    std::cin >> x[i] >> y[i] >> w[i];
    v[tot++] = x[i], v[tot++] = y[i] += n;
    --w[i], w[i] += w[i] >> 31 & mod;
  }
  std::sort(v, v + tot);
  tot = std::unique(v, v + tot) - v;
  for (int i = 0; i < k; ++i) {
    x[i] = std::lower_bound(v, v + tot, x[i]) - v;
    y[i] = std::lower_bound(v, v + tot, y[i]) - v;
    e[x[i]].emplace_back(y[i], w[i]);
    e[y[i]].emplace_back(x[i], w[i]);
  }
  prod[0] = 1;
  for (int i = 0; i < tot; ++i)
    if (!vis[i]) {
      left.clear(), right.clear();
      for (int j = 0; j < k; ++j) E[j].clear();
      dfs(i), solve();
      for (int j = 0; j <= k; ++j) tmp[j] = 0;
      for (int j = 0; j <= k; ++j)
        for (int t = 0; t + j <= k; ++t) up(tmp[j + t], ret[j], prod[t]);
      for (int j = 0; j <= k; ++j) prod[j] = tmp[j];
    }
  int ans = 0;
  for (int i = 0; i <= k && i <= n; ++i)
    ans = (prod[i] + (long long)ans * (n - i + 1)) % mod;
  for (int i = 1; i <= n - k; ++i) ans = (long long)ans * i % mod;
  std::cout << ans << '\n';
}
