#include <bits/stdc++.h>
#define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.precision(12)
using namespace std;
using ll = long long;
#define sbc __builtin_popcount
#define pb push_back
void solve() {
	int n,m;
	cin>>n>>m;
	vector<vector<pair<int,int>>> v(n+1);
	for(int i=0,x,y,z;i<m;++i) {
		cin>>x>>y>>z;
		v[x].pb({y,z});
	}
	int M=(1<<n);
	ll dp[M]{};
	dp[0]=1;
	for(int i=0;i<M;++i) {
		int p=sbc(i);
		for(auto& [y,z]:v[p]) {
			int ms=(1<<y)-1;
			if(sbc(ms&i)>z)
				dp[i]=0;
		}
		for(int x=0;x<n;++x) {
			if(!(i>>x&1)) {
				dp[i|1<<x]+=dp[i];
			}
		}
	}
	cout<<dp[M-1]<<endl;
}
int main() {
	speedup;
	//int t; cin >> t; while (t--)
	solve();
}


#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n, m;
    cin >> n >> m;

    vector< vector<int> > v(n + 1, vector<int>(n + 1, IINF));
    rep(i, m){
        int x, y, z;
        cin >> x >> y >> z;
        chmin(v[x][y], z);
    }

    vector<lint> dp(1 << n, 0);
    dp[0] = 1;

    rep(bit, 1 << n){
        vector<int> cnt(n, 0);
        rep(i, n){
            cnt[i] += bit >> i & 1;
            if(i) cnt[i] += cnt[i - 1];
        }

        rep(i, n){
            if(v[cnt[n - 1]][i + 1] < cnt[i]){
                dp[bit] = 0;
                break;
            }
        }

        rep(i, n){
            if(bit >> i & 1){
                continue;
            }

            dp[bit | (1 << i)] += dp[bit];
        }
    }

    cout << dp[(1 << n) - 1] << endl;

    cout << flush;

    return 0;
}