#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<pair<ll,ll>> cond[105];	
void solve()
{
	ll n,m;
	cin>>n>>m;
	for(ll i=1;i<=m;i++)
	{
		ll x,y,z;
		cin>>x>>y>>z;
		cond[x].push_back({y,z});
	}

	vector<ll> dp((1LL<<n),0);

	dp[0]=1;
	for(ll i=1;i<(1LL<<n);i++)
	{
		ll c=0;
		for(ll j=0;j<n;j++)
		{
			if(i&(1LL<<j)) c++;
		}

		bool ok=true;
		ll fail=-1;
		for(ll b=c;b<=n-1;b++)
		{
			for(ll j=0;j<(ll)cond[b].size();j++)
			{
				ll cnt=0;
				ll y=cond[b][j].first,z=cond[b][j].second;
				for(ll k=0;k<n;k++)
				{
					if(i&(1LL<<k))
					{
						if(k+1<=y) cnt++;
					}
				}
				//if(i==3) cout<<cnt<<"\n";

				if(cnt>z)
				{
					fail=b;
					ok=false;
					break;
				}
			}
		}
		if(!ok)
		{
			//cout<<fail<<" "<<i<<"\n";
			continue;
		}
		for(ll j=0;j<n;j++)
		{
			if(i&(1LL<<j))
			{
				dp[i]+=(dp[i^(1LL<<j)]);
			}
		}
	}
	// for(ll i=0;i<(1LL<<n);i++)
	// {
	// 	cout<<dp[i]<<" ";
	// }
	// cout<<"\n";
	cout<<dp[(1LL<<n)-1]<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=1;
	//cin>>T;
	while(T--)
	{
		//cout<<"Case #"<<p<<": ";
		solve();
		p++;
	}
	/*
	#ifndef ONLINE_JUDGE
		cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
	*/
	return 0;
}
#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
#include<map>
#include<random>
#include<complex>
#include<math.h>
#include<functional>
#include<stack>
#include<queue>
#include<unordered_map>
#include<set>
#include<numeric>
#include <cassert>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = 0x3fffffff;
const ll INF = 1e18;
int n, m; vector<vector<pair<int, int>>> p;
bool check(int msk) {
	int cnt = 0; vector<int> tp(20,0);
	rep(i, n) {
		if (msk & (1 << i)) cnt++,tp[i]++;
	}rep(i, n) tp[i + 1] += tp[i];
	for (pair<int, int> i : p[cnt]) {
		if (tp[i.first] > i.second) return false;
	}return true;
}
int main() {
	cin >> n >> m; p.resize(n + 1); vector<ll> dp(1 << n,0);
	dp[0] = 1;
	rep(i, m) {
		int x, y, z; cin >> x >> y >> z; y--;
		p[x].push_back({ y,z });
	}rep(i, 1 << n) {
		rep(j, n) if (!(i & (1 << j)) && check(i)) dp[(1<<j)| i] += dp[i];
	}cout << dp[(1 << n)-1] << endl;
}