/*Jai Shree Ram*/
// Never Give Up
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define umii            unordered_map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define F(i,s,e,j)        for(int i=s;i<=e;i+=j)
#define mt19937                 rng(chrono::steady_clock::now().tjhe_since_epoch().count());   
//shuffle(arr,arr+n,rng)
#define ld long double
 void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int dp[1<<19]; 
vector<pii> queries[101];
int cnt[19];
int solve(int bits,int n)
{
  if(dp[bits]!=-1)
  	return dp[bits];
  int num = setbits(bits);
  cnt[0] = 0;
  for(int i=1;i<=n;i++)
  {
     cnt[i] = cnt[i-1];
     if(bits&(1<<i))
     	cnt[i]++;
  }
  dp[bits] = 0;
  for(pii q:queries[num])
  {
     if(cnt[q.ff]>q.ss)
     	return 0;
  }
  if(num==n)
  	return dp[bits] = 1;
  for(int i=1;i<=n;i++)
  {
  	if((bits&(1<<i))==0)
  	{
  		dp[bits] += solve(bits|(1<<i),n);
  	}
  }
  return dp[bits];
}
int32_t main()
{   c_p_c();
     int n,m;
     cin>>n>>m;
     for(int i=0;i<m;i++)
     {
     	int x,y,z;
     	cin>>x;
        cin>>y>>z;
        queries[x].pb(mp(y,z));
     }
     memset(dp,-1,sizeof(dp));
     cout<<solve(0,n)<<endl;
} 
// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
#include <bits/stdc++.h>
#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

using namespace std;
using i64 = long long int;


int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    i64 N, M;
    cin >> N >> M;
    vector<i64> X(M), Y(M), Z(M);
    rep(i, M) cin >> X[i] >> Y[i] >> Z[i];
    vector<i64> dp(1LL<<N);
    dp[0] = 1;
    rep(i, 1LL<<N){
        i64 x = __builtin_popcount(i);
        vector<i64> c(N + 1);
        rep(k, N){
            if((i & (1LL<<k)) != 0) c[k] += 1;
            if(k != 0) c[k] += c[k - 1];
        }
        rep(k, N){
            if((i & (1LL<<k)) != 0) continue;
            rep(l, N) if(l >= k) c[l]++;
            bool flag = true;
            rep(j, M){
                if(X[j] == x + 1){
                    if(c[Y[j] - 1] > Z[j]) flag = false;
                }
            }
            if(flag) dp[i | (1LL<<k)] += dp[i];
            rep(l, N) if(l >= k) c[l]--;
        }
    }
    cout << dp[(1LL<<N) - 1] << endl;
}
