#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
#define int long long
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define F first
#define S second
#define SZ(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define LINE cout << "\n---------------\n";
#define endl cout << '\n';
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = "  << x << '\n';
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
int dp[(1<<19)];
struct T
{
	int X,Y,Z;
	T(int _x , int _y , int _z):X(_x) , Y(_y) , Z(_z){}
	T(){}
};
vector<T> limit;
signed main(){
	IOS;
	int n , m ;
	cin >> n >> m ;
	for(int i=0 ; i<m ; ++i){
		int x,y,z;
		cin >> x >> y >> z;
		limit.push_back({x,y,z});
	}
	//basic
	dp[0]=1;
	//dp
	for(int i=1 ; i<(1<<n) ; ++i){
		int bits=0;
		for(int j=0 ; j<n ; ++j){
			bits += (i >> j & 1);
		}
		bool ok = 1;
		for(int j=0 ; j<m ; ++j){
			int x = limit[j].X , y = limit[j].Y , z = limit[j].Z;
			if(bits <= x){
				int cnt=0;
				for(int k=0 ; k<y ; ++k) cnt += (i >> k & 1);
				if(cnt > z) ok = 0;
			}
		}
		if(ok){
			for(int j=0 ; j<n ; ++j){
				if(i >> j & 1){
					dp[i] += dp[i ^ (1<<j)];
				}
			}
		}
		// cout << dp[i] << '\n';
	}
	cout << dp[(1<<n)-1] << '\n';

}
#include<iostream>
#include<vector>
using namespace std;
#define popcount __builtin_popcount

int main(){
	int n,m;
	cin>>n>>m;
	int xyz[110][3];
	for(int i=0;i<m;i++)for(int j=0;j<3;j++)cin>>xyz[i][j];
	int n2=1<<n;
	long long mask[110]={0};
	vector<long long> dp(n2);
	for(int i=0;i<n;i++)mask[i+1]=mask[i]<<1|1;
	dp[0]=1;
	for(int s=0;s<n2;s++){
		int x=popcount(s);
		for(int i=0;i<m;i++){
			if(x==xyz[i][0])
			if(popcount(s&mask[xyz[i][1]])>xyz[i][2])dp[s]=0;
		}
		for(int i=0;i<n;i++){
			if(~s>>i&1){
				dp[s|1<<i]+=dp[s];
			}
		}
	}cout<<dp.back()<<endl;
	return 0;
}
