#include<iostream>
#include<iomanip>

#include<cmath>
#include<algorithm>
#include<numeric>

#include<vector>
#include<string>
#include<set>
#include<map>
//#include<atcoder/all>

#define fi first
#define se second
#define pb(x) emplace_back(x)

using namespace std;
using ll = long long;
using v_ll = vector <ll>;

bool IS_TEST=false;
ll INF = ll(1e17);

ll max(ll x,ll y){return x>y?x:y;}
ll min(ll x,ll y){return x<y?x:y;}
template<class T> bool chmax(T& x,const T& y){ if (x>=y) return false; x=y; return true;}
template<class T> bool chmin(T& x,const T& y){ if (x<=y) return false; x=y; return true;}
template<class T> void quit(T x){std::cout << x << "\n"; exit(0);}

template<typename T> void vshow(T x){for(auto itr = x.begin();itr!=x.end();itr++){std::cerr << *itr << " ";} std::cerr << "\n";}
template<typename T> void vvshow(T x){for(auto itr = x.begin();itr!=x.end();itr++){vshow(*itr);} std::cerr << "\n";}

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N,M;
  cin >> N >> M;
  v_ll X(M,0),Y(M,0),Z(M,0);
  for(ll i=0;i<M;i++) cin >> X[i] >> Y[i] >> Z[i];
  v_ll ans(1LL<<N,0);
  ans[0]=1;
  for(ll i=1;i<(1LL<<N);i++){
    ll c=0,ii=i;

    v_ll cnt(N+1,0);
    for(ll k=1;k<=N;k++){
      cnt[k]=cnt[k-1];
      if (ii&1){c++;cnt[k]++;}
      ii>>=1;
    }
    ll flg = true;
    for(ll j=0;j<M;j++){
      if (c!=Y[j]) continue;
      if (cnt[X[j]]>Z[j])flg = false;
    }
    if (flg){
      ll p=0;
      for(ll j=0;j<N;j++){
        p+=ans[i&(-1-(1LL<<j))];
      }
      ans[i]=p;
    }
  }
  cout << ans[(1LL<<N)-1] <<"\n";
}



#include <iostream>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <bits/stdc++.h>
#include <vector>
#include <array> 
#include <tuple>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;
typedef long long ll;

int main() {
  int N, p, t;
  cin >> N;
  ll l[N], r[N], y, z;
  ll ans;
  ans=0;
  for (int i=0; i<N; i++){
    cin >> t >> y >> z;
    if (t==1){
      l[i]=2*y;
      r[i]=2*z;
    }
    if (t==2){
      l[i]=2*y;
      r[i]=2*z-1;
    }
    if (t==3){
      l[i]=2*y+1;
      r[i]=2*z;
    }
    if (t==4){
      l[i]=2*y+1;
      r[i]=2*z-1;
    }
  }
  for (int i=0; i<N-1; i++){
    for (int j=i+1; j<N; j++){
      p=1;
      if (r[i]<l[j]){
        p=0;
      }
      if (r[j]<l[i]){
        p=0;
      }
      ans+=p;
    }
  }
  cout << ans << endl;
}