#include <stdio.h>
#include <vector>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;

int main(void) {
  ll i, j, n, m, x, y, z, cnt;
  scanf("%lld%lld", &n, &m);
  vector<pl> vec[n + 1];
  ll dp[1 << n], sum[n];
  for(i = 0; i < 1 << n; ++i) dp[i] = 0;
  dp[0] = 1;
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld%lld", &x, &y, &z);
    vec[x].push_back(make_pair(--y, z));
  }
  for(i = 0; i < 1 << n; ++i) {
    cnt = 0;
    for(j = 0; j < n; ++j) {
      sum[j] = i & (1 << j) ? 1 : 0, cnt += sum[j];
      if(j) sum[j] += sum[j - 1];
    }
    for(j = 0; j < vec[cnt].size(); ++j) 
      if(sum[vec[cnt][j].first] > vec[cnt][j].second) dp[i] = 0;
    if(dp[i]) for(j = 0; j < n; ++j) if(!(i & (1 << j))) dp[i | (1 << j)] += dp[i];
  }
  printf("%lld", dp[(1 << n) - 1]);
  return 0;
}
#pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vii = V<int>;
using vvll = V<vll>;
using vvii = V< V<int> >;
using PII = P<int, int>;
using PLL = P<ll, ll>;
#define RevREP(i,n,a) for(ll i=n;i>a;i--)  // (a,n]
#define REP(i,a,n) for(ll i=a;i<n;i++)  // [a,n)
#define rep(i, n) REP(i,0,n)
#define ALL(v) v.begin(),v.end()
#define eb emplace_back
#define pb push_back
#define sz(v) int(v.size())

template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
template< class A, class B > ostream& operator <<(ostream& out, const P<A, B> &p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template< class A > ostream& operator <<(ostream& out, const V<A> &v) {
    out << '[';
    for (int i=0;i<int(v.size());i++) {
        if (i) out << ", ";
        out << v[i];
    }
    return out << ']';
}

template<class A, class B> istream& operator >>(istream& in, P<A, B> &p) {
    return in >> p.first >> p.second;
}
template<class A> istream& operator >>(istream& in, V<A> &v) {
    for (int i = 0; i < int(v.size()); i++) in >> v[i];
    return in;
}

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    V< V<PII> > xyz(n + 1);
    rep(i, m) {
        int x, y, z; cin >> x >> y >> z;
        xyz[x].eb(PII(y - 1, z));
    }
    
    vll dp(1 << n, 0);
    dp[0] = 1;
    rep(bit, 1 << n) {
        int tx = __builtin_popcount(bit);
        rep(i, n) {
            if (!(bit >> i & 1)) {
                ll tobit = bit | (1 << i);
                vii acc(n, 0);
                rep(j, n) if (tobit >> j & 1) acc[j]++;
                rep(j, n - 1) acc[j + 1] += acc[j];
                bool ok = true;
                for (auto [y, z]: xyz[tx + 1]) {
                    if (acc[y] > z) ok = false;
                }
                if (ok) dp[tobit] += dp[bit];
            }
        }
    }
    cout << dp.back() << '\n';
    return 0;
}
