#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, k;
vector<int> x, y;
const int MOD = 1000000007;
map<long long, int> dp[55][55];
vector<pair<int, int> > g[55];
int fac[100000 + 20];
long long have[55];
int main() {
  scanf("%d%d", &n, &k);
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % MOD;
  vector<pair<pair<int, int>, int> > e;
  for (int i = 1; i <= k; ++i) {
    int xi, yi, wi;
    scanf("%d%d%d", &xi, &yi, &wi);
    x.push_back(xi);
    y.push_back(yi);
    e.push_back(make_pair(make_pair(xi, yi), wi - 1));
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  for (auto& it : e) {
    it.first.first =
        lower_bound(x.begin(), x.end(), it.first.first) - x.begin();
    it.first.second =
        lower_bound(y.begin(), y.end(), it.first.second) - y.begin();
    g[it.first.first].push_back({it.first.second, it.second});
  }
  int sz = x.size();
  for (int i = sz - 1; i >= 0; --i) {
    have[i] = have[i + 1];
    for (auto it : g[i]) have[i] |= 1ll << it.first;
  }
  dp[0][0][0] = 1;
  for (int i = 0; i <= sz - 1; ++i) {
    for (int j = 0; j <= sz; ++j) {
      for (auto sta = dp[i][j].begin(); sta != dp[i][j].end(); sta++) {
        dp[i + 1][j][sta->first & (have[i + 1])] += sta->second;
        if (dp[i + 1][j][sta->first & (have[i + 1])] >= MOD)
          dp[i + 1][j][sta->first & (have[i + 1])] -= MOD;
        for (auto it : g[i]) {
          int nex = it.first;
          int w = it.second;
          if (((sta->first) >> nex) & 1)
            ;
          else
            (dp[i + 1][j + 1][(sta->first | 1ll << nex) & (have[i + 1])] +=
             1ll * sta->second * w % MOD) %= MOD;
        }
      }
    }
  }
  int rest = 0;
  for (int i = 0; i <= sz; ++i) {
    (rest += 1ll * fac[n - i] * dp[sz][i][0] % MOD) %= MOD;
  }
  cout << rest << endl;
  return 0;
}
