#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<i64> dp(1 << n);
  vector<vector<pair<int, int>>> conds(1 + n);
  while (m--) {
    int x, y, z;
    cin >> x >> y >> z;
    conds[x].emplace_back(y, z);
  }
  dp[0] = 1;
  for (int s = 0; s < 1 << n; s++) {
    for (auto [y, z] : conds[__builtin_popcount(s)]) {
      for (int i = 0; i < y; i++) {
        if (s >> i & 1) z--;
      }
      if (z < 0) dp[s] = 0;
    }
    for (int j = 0; j < n; j++)
      if (~s >> j & 1) {
        dp[s | 1 << j] += dp[s];
      }
  }
  cout << dp.back() << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  solve();
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll N, M;
    cin >> N >> M;
    using P = pair<ll, ll>;
    vector<P> YZ[30];
    REP(i,M){
        ll x, y, z;
        cin >> x >> y >> z;
        //x--;
        YZ[x].push_back(P(y, z));
    }

    vector<ll> DP(1 << N);
    DP[0] = 1;
    for(int b = 0; b < (1 << N); b++){
        ll pop = __builtin_popcount(b);
        for(int v = 0; v < N; v++){
            if((b >> v) & 1) continue;
            bool valid = true;
            for(auto& [y, z] : YZ[pop+1]){
                ll num = 0;
                if(v+1 <= y) num++;
                for(int x = 0; x < y; x++){
                    if((b >> x) & 1)
                        num++;
                }

                if(num > z)
                    valid = false;
            }

            if(valid){
                DP[b | (1 << v)] += DP[b];
            }
        }
    }

    ll ans = DP[(1 << N) - 1];
    cout << ans << endl;
    return 0;
}
