#include <bits/stdc++.h>

using namespace std ;

const int MAX = 20 ;

int n , m ;
long long dp[1 << MAX] ;

vector< pair<int , int> >v[MAX] ;

long long solve(int mask)
{
	if(mask == ((1 << n) - 1))
		return 1 ;
	long long &ret = dp[mask] ;
	if(ret != -1)
		return ret ;
	ret = 0 ;
	int idx = __builtin_popcount(mask) ;
	for(auto &p : v[idx])
	{
		int y = p.first , z = p.second ;
		int cnt = 0 ;
		for(int bit = 0 ; bit < y ; ++bit)
		{
			if((mask & (1 << bit)))
				cnt++ ;
		}
		if(cnt > z)
			return 0 ;
	}
	for(int bit = 0 ; bit < n ; ++bit)
	{
		if((mask & (1 << bit)))
			continue ;
		ret += solve(mask | (1 << bit)) ;
	}
	return ret ;
}

int main()
{
	memset(dp , -1 , sizeof(dp)) ;
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	for(int i = 0 ; i < m ; ++i)
	{
		int x , y , z ;
		cin>>x>>y>>z ;
		v[x].emplace_back(y , z) ;
	}
	return cout<<solve(0)<<"\n" , 0 ;
}		
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>
#include<vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


ll dp[1 << 18];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N, M;
	cin >> N >> M;

	vector<pair<int, int>> XYZ[20];
	rep(i, M) {
		int x, y, z;
		cin >> x >> y >> z;
		XYZ[y].pb({ x, z });
	}

	dp[0] = 1;
	rep(i, 1 << N) {
		int c = __builtin_popcount(i);
		int OK = 1;
		for (auto p : XYZ[c]) {
			if (__builtin_popcount(i << 32 - p.first) > p.second) {
				OK = 0;
				break;
			}
		}
		if (!OK) {
			dp[i] = 0;
		}
		else {
			int tmp = i;
			for(int j = i + 1; j < (1 << N); j = tmp + 1) {
				dp[i | j] += dp[i];
				tmp |= j;
			}
		}
	}
	co(dp[(1 << N) - 1]);


	Would you please return 0;
}