#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int> 
#define v(s) vector<s>
#define rsz(a,n) a.resize(n)
#define rszv(a,n,v) a.resize(n,v)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//eodefine

const int max_n = 100 , max_m=500000;

using namespace std;
int n,m;
v(pii) a[max_n];

void rdd(){
	cin>>n>>m;

	rep(i,m) {
		int x,y,z;
		cin>>x>>y>>z;
		y--;
		a[x].pb({y,z});
	}
	
}
bool ok(int msk, v(pii) t) {
	for(auto p : t) {
		int cnt=0;
		rep(i,n) {
			if(msk&(1<<i)) {
				if(i<=p.fi)cnt++;
			}
		}
		if(cnt>p.se)return 0;
	}
	return 1;
}

ll dp[max_n][max_m];

int main(){
fcin;
	rdd();
	
	dp[0][0]=1;
	// cout<<(1<<n) <<"|n"
	ll fll=(1<<n);
	// cout<<fll<<"\n";
	rep(i,n+1){
		rep(msk,(1<<n)) {
			int k=__builtin_popcount(msk);
			if(dp[i][msk] == 0 or ok(msk,a[i]) == 0 or k!=i)continue;

			rep(x,n) {
				if(msk&(1<<x)) continue;
				dp[i+1][msk|(1<<x)] += dp[i][msk];
				// cout<<dp[i][msk]<<"\n";
			}
		}
	
	}
	
	ll ans=0;

	rep(msk,(1<<n)) {
		ans+=dp[n][msk];
	}

	cout<<ans<<"\n";
/*






*/

    return 0;   
}
#include<bits/stdc++.h>
using namespace std;
using P = pair<int64_t,int64_t>;
const int MAX = (1<<19);
int64_t dp[MAX];
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<P>> vec(N,vector<P>(0));
  for(int i=0; i<M; i++){
    int X, Y, Z;
    cin >> X >> Y >> Z;
    X--;
    vec[X].push_back(P(Y,Z));
  }
  dp[0] = 1;
  for(int i=0; i<(1<<N); i++){
    int c = 0;
    vector<int> sum(N);
    for(int j=0; j<N; j++){
      if(i & (1<<j)){
        c++;
        sum[j]++;
      }
      if(j != 0){
        sum[j] += sum[j-1];
      }
    }
    //何を追加するか？
    for(int j=0; j<N; j++){
      if(i & (1<<j)){
        continue;
      }
      bool flag = true;
      for(int k=0; k<vec[c].size(); k++){
        auto[y,z] = vec[c][k];
        if(j < y){
          z--;
        }
        if(sum[y-1] > z){
          flag = false;
          break;
        }
      }
      if(flag){
        dp[i|(1<<j)] += dp[i];
      }
    }
  }
  cout << dp[(1<<N)-1] << endl;        
}
  