#include <bits/stdc++.h>
using namespace std;
const int K = 110, N = 201000;
const int mod = 1000000007;
long long fac[N];
int n, k;
int l, r, ans, a[K][K], cp[K];
vector<int> dp[K][K];
inline void upd(int &a, long long b) { a = (a + b) % mod; }
int pos[K], p[K], od[K], id[K][K];
long long cost[K];
vector<int> _e[K], pnt[K];
long long calc(int t = 0) {
  for (int i = 0; i < l + r; i++) pos[p[i]] = i, cost[i] = 1;
  for (int i = 0; i < l + r; i++) {
    int ms = i;
    for (int j = 0; j < ((int)(_e[p[i]]).size()); j++)
      ms = max(ms, pos[_e[p[i]][j]]);
    for (int j = i; j < ms + 1; j++) cost[j] *= 2;
  }
  long long ret = 0;
  for (int i = 0; i < l + r; i++) ret += cost[i];
  return ret;
}
void solve() {
  for (int i = 0; i < l + r; i++) _e[i].clear();
  for (int i = 0; i < l; i++)
    for (int j = 0; j < r; j++)
      if (a[i][j] != 1) _e[i].push_back(j + l), _e[j + l].push_back(i);
  for (int i = 0; i < l + r; i++) p[i] = i, od[i] = i;
  long long ans = calc();
  for (int k = 0; k < 100000; k++) {
    int u = rand() % (l + r), v = rand() % (l + r);
    for (int i = 0; i < l + r; i++) p[i] = od[i];
    swap(p[u], p[v]);
    long long c = calc();
    if (c < ans) {
      ans = c;
      for (int i = 0; i < l + r; i++) od[i] = p[i];
    }
  }
  int cl = 0, cr = 0;
  for (int i = 0; i < l + r; i++) p[i] = od[i], pnt[i].clear();
  ;
  for (int i = 0; i < l + r; i++) pos[p[i]] = i;
  for (int i = 0; i < l + r; i++)
    for (int j = 0; j < l + r; j++) id[i][j] = -1;
  for (int i = 0; i < l + r; i++) {
    int ms = i;
    for (int j = 0; j < ((int)(_e[p[i]]).size()); j++)
      ms = max(ms, pos[_e[p[i]][j]]);
    for (int j = i; j < ms + 1; j++) pnt[j].push_back(i);
  }
  for (int i = 0; i < l + r; i++)
    for (int j = 0; j < ((int)(pnt[i]).size()); j++) id[i][pnt[i][j]] = j;
  dp[0][0].clear();
  dp[0][0].resize(2);
  dp[0][0][0] = 1;
  if (p[0] < l)
    cl++;
  else
    cr++;
  for (int i = 1; i < l + r; i++) {
    int u = p[i];
    for (int k = 0; k < min(cl, cr) + 2; k++) {
      dp[i][k].clear();
      dp[i][k].resize((1 << (((int)(pnt[i]).size()))));
    }
    for (int oS = 0; oS < (1 << (((int)(pnt[i - 1]).size()))); oS++) {
      int S = 0, pl = cl, pr = cr;
      for (int w = 0; w < ((int)(pnt[i - 1]).size()); w++)
        if (oS & (1 << (w))) {
          int ps = id[i][pnt[i - 1][w]];
          if (ps != -1) S |= 1 << ps;
        }
      for (int w = 0; w < ((int)(pnt[i]).size()) - 1; w++)
        if (!(S & (1 << (w)))) {
          int v = p[pnt[i][w]];
          if (v < l)
            pl--;
          else
            pr--;
        }
      for (int k = 0; k < min(cl, cr) + 1; k++)
        if (dp[i - 1][k][oS]) {
          long long ret = dp[i - 1][k][oS];
          upd(dp[i][k][S], ret);
          for (int w = 0; w < ((int)(pnt[i]).size()) - 1; w++)
            if (!(S & (1 << (w)))) {
              int v = p[pnt[i][w]];
              if (((u < l) ^ (v < l)) == 0) continue;
              upd(dp[i][k + 1]
                    [S | (1 << (((int)(pnt[i]).size()) - 1)) | (1 << (w))],
                  ret * ((u < l) ? a[u][v - l] : a[v][u - l]));
            }
          if (u < l)
            upd(dp[i][k + 1][S | (1 << (((int)(pnt[i]).size()) - 1))],
                ret * (pr - k));
          else
            upd(dp[i][k + 1][S | (1 << (((int)(pnt[i]).size()) - 1))],
                ret * (pl - k));
        }
    }
    if (p[i] < l)
      cl++;
    else
      cr++;
  }
  for (int j = 0; j < min(cl, cr) + 1; j++)
    for (int k = 0; k < (1 << (((int)(pnt[l + r - 1]).size()))); k++)
      upd(cp[j], dp[l + r - 1][j][k]);
}
map<int, int> vecr, vecc;
int x, y, w;
long long perm(int a, int b) {
  long long s = 1;
  for (int j = 1; j < b + 1; j++) s = s * (a + 1 - j) % mod;
  return s;
}
int main() {
  scanf("%d%d", &n, &k);
  fac[0] = 1;
  for (int i = 1; i < n + 1; i++) fac[i] = fac[i - 1] * i % mod;
  vecr.clear();
  vecc.clear();
  for (int i = 0; i < k; i++)
    for (int j = 0; j < k; j++) a[i][j] = 1;
  l = 0;
  r = 0;
  for (int i = 0; i < k; i++) {
    scanf("%d%d%d", &x, &y, &w);
    if (!vecr.count(x)) vecr[x] = l++;
    if (!vecc.count(y)) vecc[y] = r++;
    a[vecr[x]][vecc[y]] = w;
  }
  solve();
  for (int j = 0; j <= l && j <= r; j++) {
    if (l + r - j > n) continue;
    upd(ans, 1ll * cp[j] * perm(n - r, l - j) % mod * perm(n - l, r - j) % mod *
                 fac[n - r - l + j] % mod);
  }
  printf("%d\n", ans);
}
