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

const int maxn = 1 << 19;

int n, m;
long long dp[maxn]; bool ok[maxn];
int x[110], y[110], z[110];

int main()
{
    scanf ("%d %d", &n, &m);
    for (int i = 1; i <= m; i++)
        scanf ("%d %d %d", x + i, y + i, z + i);
    int upp = 1 << n;
    dp[0] = 1;
    for (int sta = 0; sta < upp; sta++)
    {
        bool f = 1;
        int cnt = __builtin_popcount(sta);
        for (int i = 1; i <= m; i++)
        {
            if (cnt > x[i]) continue;
            int c = 0;
            for (int o = 0; o < y[i]; o++) if ((1 << o) & sta) c++;
            if (c > z[i]) f = 0;
        }
        if (!f) dp[sta] = 0;
        for (int o = 0; o < n; o++) if (!((1 << o) & sta)) dp[sta | (1 << o)] += dp[sta];
    }
    printf ("%lld\n", dp[upp - 1]);
    return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 19;
const int MAX_M = 105;
ll dp[(1 << MAX_N)];
int X[MAX_M],Y[MAX_M],Z[MAX_M];

int main()
{
	int N,M;
	cin >> N >> M;
	rep(i,M)
	{
		cin >> X[i] >> Y[i] >> Z[i];
		//X[i] = i%(N-1)+1; Y[i] = i%(N-1)+1; Z[i] = i%N;
	}
	dp[0] = 1;
	for (int bits = 0; bits < (1 << N); ++bits)
	{
		vector<int> ppcnt(N+1,0);
		rep(i,N) {ppcnt[i+1] = ppcnt[i] + ((bits >> i) & 1);}
		/*
		rep(i,N+1) cout << ppcnt[i] << " ";
		cout << endl;
		*/
		rep(i,N)
		{
			if ((bits >> i) & 1 != 0) continue;
			bool ok = true;
			int c;
			rep(j,M)
			{
				if (i+1 <= Y[j]) c = 1;
				else c = 0;
				if (X[j] == ppcnt[N]+1 && ppcnt[Y[j]]+c > Z[j]) ok = false;
			}
			if (ok) dp[bits | (1 << i)] += dp[bits];
		}
		//cout << bits << " " << dp[bits] << endl;
	}
	cout << dp[(1 << N) - 1] << endl;
	return 0;
}