#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define srt(v)  if(!v.empty())sort(v.begin(),v.end())
#define rev(v)  if(!v.empty())reverse(v.begin(),v.end())
#define PI 3.141592653589793238
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}

ll inv_mod(ll x){
    return pow_mod(x,mod-2);
}

const ll N=19;
ll inv[N];
ll fac[N];

ll ncr(ll n,ll r){
    if(n<r)
    return 0;

    if(n==r||r==0)
    return 1LL;

    ll x=fac[n];
    ll y=inv[n-r];
    ll z=inv[r];

    return ((x*y)%mod*z)%mod;
}

void solve()
{  
/*
   3 1
2 2 1
0

*/
   ll n,m;
   cin>>n>>m;
   
   if(m==0)
   {
   	cout<<fac[n]<<endl;
   	return;
   }
   ll x[m+1],y[m+1],z[m+1];
   
   for(ll i=0;i<m;i++)
   cin>>x[i]>>y[i]>>z[i];
   
   
   vector<pii>v[n+1];
   
   for(ll i=0;i<m;i++){
   	--x[i];
   	v[x[i]].pb({y[i],z[i]});
   }
   ll ans=0;
   
   ll dp[(1LL<<n)+1][n+1];
   memset(dp,0,sizeof(dp));
   
   for(ll i=0;i<n;i++){
   	   for(ll j=1;j<(1LL<<n);j++){
   	   	     ll cnt=__builtin_popcountll(j);
   	   	     if(cnt!=i+1)
   	   	     continue;
   	   	     bool f=true;
   	   	     for(auto each:v[i]){
   	   	     	     ll lim=each.ff;
   	   	             ll cur=j%(1LL<<lim);
   	   	             ll cnt_now=__builtin_popcountll(cur);
   	   	             if(cnt_now>each.ss){
   	   	             	f=false;
   	   	             	break;
						   }
				   }
				   if(f==false){
				   	continue;
				   }
				   
			////	   cout<<j<<" "<<i<<endl;
				   
				   for(ll k=0;k<n;k++){
				   	  if(j&(1LL<<k)){
				   	  	   ll prev_pot=j^(1LL<<k);
				   	  	   if(i)
				   	  	   dp[j][i]+=dp[prev_pot][i-1];
				   	  	   else
				   	  	   dp[j][i]+=1;
						 }
				   }
   	   	     
		  }
   }
   
  // cout<<dp[0][1]<<endl;
   
   ans=dp[(1LL<<n)-1][n-1];
   cout<<ans<<endl;
}
int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);

//Start from Here.
    fac[0]=1;

  for(ll i=1;i<N;i++)
  fac[i]=(i*fac[i-1]);


  ll t;
  t=1;
 // cin>>t;
  while(t--)
  solve();






//Good Bye!
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for (int i=0; i<n; i++)
#define all(vec) vec.begin(), vec.end()
#define pcnt __builtin_popcount

int main() {
  int N,M;
  cin >> N >> M;
  vector<vector<P>> ps(N+1);
  rep(i, M) {
    int x,y,z;
    cin >> x >> y >> z;
    ps[x].emplace_back(y,z);
  }
  int N2 = 1<<N;
  vector<ll> dp(N2);
  dp[0] = 1;
  vector<int> mask(N+1);
  rep(i,N) mask[i+1] = mask[i]<<1|1;
  rep(s,N2) {
    int c = pcnt(s);
    for (P p : ps[c]) {
      if (pcnt(s&mask[p.first]) > p.second) dp[s] = 0;
    }
    rep(j,N) if (~s>>j&1) {
      dp[s|1<<j] += dp[s];
    }
  }
  cout << dp.back() << endl;
  return 0;
}
