#include <iostream>
#include <vector>
using namespace std;

struct cond {
	int X, Y, Z;
};

bool IsOneBit(long long bits, int i) {
	return (bits & (1ll << i)) > 0;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<cond> Cond(M);
	for (auto& [X, Y, Z] : Cond) cin >> X >> Y >> Z;
	int PN = 1 << N;
	vector<long long> DP(PN);
	DP[0] = 1;
	for (int bit = 0; bit < PN; bit++) {
		int one = 0;
		for (int i = 0; i < N; i++) one += IsOneBit(bit, i);
		bool isOK = true;
		for (auto& [X, Y, Z] : Cond) {
			if (one > X) continue;
			int sum = 0;
			for (int j = 0; j < Y; j++) sum += IsOneBit(bit, j);
			if (sum > Z) isOK = false;
		}
		if (isOK) {
			for (int i = 0; i < N; i++) {
				if (IsOneBit(bit, i)) DP[bit] += DP[bit ^ (1 << i)];
			}
		}
		else DP[bit] = 0;
	}
	cout << DP[PN - 1] << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<int> X(m), Y(m), Z(m);
  vector<vector<pair<int, int>>> A(n+1);
  rep(i, m) {
    cin >> X[i] >> Y[i] >> Z[i];
    Y[i]--;
    A[X[i]].push_back({Y[i], Z[i]});
  }
  vector<ll> dp(1<<n);
  dp[0] = 1;
  rep(i, 1<<n) {
    rep(j, n) {
      if((i>>j)&1) continue;
      vector<int> cnt(n);
      int ne = i^(1<<j);
      rep(k, n) {
        if((ne>>k)&1) cnt[k]++;
      }
      rep(k, n) if(k) cnt[k] += cnt[k-1];
      bool ok = true;
      int sz = __builtin_popcount(ne);
      for(auto [y, z]: A[sz]) {
        if(cnt[y] > z) ok = false;
      }
      if(ok) dp[ne] += dp[i];
    }
  }
  cout << dp[(1<<n)-1] << endk;
  return 0;
}
