#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define all(v) v.begin(),v.end()

const int mod = 1e9 + 7;
ll dp[(1 << 18)][18];
int main (){
    fast_io;
    ll n, m;
    cin >> n >> m;
    vector<vector<int> > constraints;
    for (int i = 0; i < m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        constraints.push_back({x, y, z});
    }
    dp[0][0] = 1;
    for (int i = 0; i < (1 << n); i++) {
        int pref[n];
        memset(pref, 0, sizeof(pref));
        for (int j = 0; j < n; j++) {
            if (i & (1 << j))
                pref[j]++;
        }
        for (int j = 1; j < n; j++)
            pref[j] += pref[j - 1];
        for (int j = 0; j < n; j++) {
            if (dp[i][j] == 0)
                continue;
            for (int k = 0; k < n; k++) {
                if ((i & (1 << k)))
                    continue;
                bool flag = false;
                int len = __builtin_popcount(i);
                for (auto& constraint: constraints) {
                    if (len != constraint[0])
                        continue;
                    if ((k <= constraint[1] && constraint[2] == pref[constraint[1]]) ||
                       (constraint[2] < pref[constraint[1]])) {
                        flag = true;
                        break;
                    }
                }
                if (flag == true)
                    continue;
                dp[i | (1 << k)][k] += dp[i][j];
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += dp[(1 << n) - 1][i];
    }
    cout << ans << endl;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N,M;
    cin >> N >> M;
    vector<vector<PII>> yz(N);
    
    REP(i,M){
        int x,y,z;
        cin >> x >> y >> z;
        x--;
        yz[x].eb(y,z);
    }
    vector<vector<LL>> dp(N+1,VL(1 << N));
    dp[0][0] = 1;
    REP(i,N){
        REP(mask,(1 << N)){
            REP(j,N){
                if((mask >> j) & 1) continue;
                dp[i+1][mask | (1 << j)] += dp[i][mask];
            }
        }

        // check
        REP(mask, (1 << N)){
            bool ok = true;
            for(auto p : yz[i]){
                int y,z;
                tie(y,z) = p;
                int cnt = 0;
                REP(a,y){
                    if((mask >> a) & 1) cnt++;
                }
                if(cnt > z) ok = false;
            }

            if(!ok){
                dp[i+1][mask] = 0;
            }
        }
    }

    //REP(i,N+1){
    //    dump(i)
    //    REP(mask, (1 << N)){
    //        cout << mask << " " << dp[i][mask] << endl;
    //    }
    //}

    LL ans = 0;
    REP(mask, (1 << N)){
        ans += dp[N][mask];
    }
    cout << ans << endl;

}