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

#define ll              long long 
#define pb              push_back
#define all(v)          v.begin(),v.end()
#define sz(a)           (ll)a.size()
#define F               first
#define S               second
#define INF             2000000000000000000
#define popcount(x)     __builtin_popcountll(x)
#define pll             pair<ll,ll> 
#define pii             pair<int,int>
#define ld              long double

const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

const int N = 18;

int dp[1<<N][101];

int x[101],y[101],z[101];

vector<int> v[N];

ll ans[N+2][1<<N];

int _runtimeTerror_()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;++i)
    {
        cin>>x[i]>>y[i]>>z[i];
        --y[i];
        v[x[i]].push_back(i);
    }
    for(int i=0;i<(1<<n);++i)
    {
        for(int j=0;j<m;++j)
        {
            if(popcount(i)+1 == x[j])
            {
                int al = 0;
                for(int k=0;k<n;++k)
                {
                    if(i&(1<<k))
                        al += k <= y[j];
                }
                if(al > z[j])
                    continue;
                for(int k=0;k<n;++k)
                {
                    if(i&(1<<k))
                        continue;
                    al += k <= y[j];
                    if(al <= z[j])
                        dp[i][j] ^= (1<<k); 
                    al -= k <= y[j];
                }
            }
        }
    }
    ans[0][0] = 1;
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<(1<<n);++j)
        {
            int can = (1<<n)-1;
            for(auto &k:v[i+1])
                can &= dp[j][k];
            for(int k=0;k<n;++k)
            {
                if(can&(1<<k))
                    ans[i+1][j^(1<<k)] += ans[i][j];
            }
        }
    }
    cout<<ans[n][(1<<n)-1]<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b); i-- > (a); )
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

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

	vector<vector<pair<int, int>>> constraint(n); 
	rep(i, 0, m) {
		int x, y, z; cin >> x >> y >> z;
		constraint[--x].emplace_back(y, z);
	}

	vector<ll> dp(1 << n);
	dp[0] = 1;
	rep(S, 0, 1 << n) {
		int x = __builtin_popcount(S);
		rep(i, 0, n) {
			if (S >> i & 1) continue;

			int T = S | 1 << i;
			bool valid = 1;
			for (auto [y, z] : constraint[x])
				valid &= __builtin_popcount(T & ((1 << y) - 1)) <= z;
			if (valid) dp[T] += dp[S];
		}
	}

	cout << dp.back() << '\n';
}