#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
 
using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())
#define Output(a) cout << a << endl
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<long long> vll;
 
const ll INF = 0x1fffffffffffffff;
const ll MOD = 1000000007;
 
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; }

int main() {
    ll n, m;
    cin >> n >> m;
    vll x(m), y(m), z(m);
    rep(i, m){
        cin >> x[i] >> y[i] >> z[i];
        x[i]--;
    }
 
    ll dp[n + 1][(1 << n)];
    rep(i, n + 1){
        rep(j, 1 << n){
            dp[i][j] = 0;
        }
    }
 
    dp[0][0] = 1;
    rep(i, n){
        rep(j, 1 << n){
            for (int k = 0; k < n; k++) {
                if (!(j & (1 << k))) dp[i + 1][j + (1 << k)] += dp[i][j];
            }
        }
 
        rep(j, m){
            if(x[j] == i){
                rep(bit, 1 << n){
                    int cnt = 0;
                    for(ll k = 0; k < y[j]; k++){
                        if (bit & (1 << k)) cnt++;
                    }
                    if (cnt > z[j]) {
                        dp[i + 1][bit] = 0; 
                    }
                }
            }
        }
    }
 
    cout << dp[n][(1 << n) - 1] << endl;
}

// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue> 
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl
 
const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001 
  
// stores smallest prime factor for every number 
 
 
ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}
 
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends
const int MN = 2e5+7;
ll dp[1 << 21];
ll fun(ll mask, ll n, vector <pii> v[]) {
    int i=__builtin_popcount(mask);
    if (i== n) {
        return 1;
    }
    if (dp[mask] != -1) {
        return dp[mask];
    }
    ll temp = 0;
    ll cnt = 0;
    for (auto j: v[i]) {
        cnt = 0;
        for (ll k = 1; k <= j.ff; k++) {
            if (mask & (1LL << k)) {
                ++cnt;
            }
        }
        if (cnt > j.ss) {
            temp = -1e18;
        } 
    }
    for (ll j = 0; j < n; j++) {
        if (mask & (1LL << j)) {
            continue;
        }
        temp+=fun( mask | (1LL << j), n, v);
    }
    temp = max(temp, 0LL);
    return dp[mask] = temp;
}
void solve(){
    ll n,m; cin>>n>>m;
    ll ans;
    if (!m) {
        ans = 1;
        for (ll i = 1; i <= n; i++) {
            ans *= i;
        }
        cout<<ans<<endl;
        return;
    }
    vector <pii> v[20];
    for (ll i = 0; i < m; i++) {
        int x,y,z; cin>>x>>y>>z;
        v[x].pb(mp(y,z));
    }
    memset(dp, -1, sizeof(dp));
    ans = fun( 0, n, v);
    cout<<ans<<endl;
}
int main(){
    fastio();
    //write code
    solve();
    return 0;
}