#include <bits/stdc++.h>
using namespace std;
const int N = 100100, M = 60, mod = 1e9 + 7;
inline void mul_add(int& x, const int& y, const int& z) {
  x = ((long long)x + (long long)y * z) % mod;
}
inline void reduce(int& x) { x += x >> 31 & mod; }
int u[M], v[M], w[M], A[M], B[M], fac[N], n, m, ans;
vector<pair<int, int> > G[M];
map<long long, int> dp[M][M];
long long f[M];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = (long long)fac[i - 1] * i % mod;
  for (int i = 1; i <= m; ++i) {
    cin >> u[i] >> v[i] >> w[i];
    --w[i];
    A[i] = u[i];
    B[i] = v[i];
  }
  sort(A + 1, A + m + 1);
  sort(B + 1, B + m + 1);
  int cx = unique(A + 1, A + m + 1) - A - 1;
  int cy = unique(B + 1, B + m + 1) - B - 1;
  for (int i = 1; i <= m; i++) {
    u[i] = lower_bound(A + 1, A + cx + 1, u[i]) - A - 1;
    v[i] = lower_bound(B + 1, B + cy + 1, v[i]) - B - 1;
    G[u[i]].push_back(make_pair(v[i], w[i]));
  }
  for (int i = cx - 1; i >= 0; --i) {
    f[i] = f[i + 1];
    for (auto j : G[i]) f[i] |= 1ll << j.first;
  }
  dp[0][0][0] = 1;
  for (int i = 0; i < cx; i++) {
    for (int j = 0; j <= i; j++) {
      for (auto k : dp[i][j]) {
        reduce(dp[i + 1][j][k.first & f[i + 1]] += k.second - mod);
        for (auto l : G[i]) {
          if (!(k.first >> l.first & 1))
            mul_add(dp[i + 1][j + 1][(k.first | (1ll << l.first)) & f[i + 1]],
                    k.second, l.second);
        }
      }
    }
  }
  for (int i = 0; i <= cx; ++i) mul_add(ans, fac[n - i], dp[cx][i][0]);
  cout << ans << '\n';
  return 0;
}
