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

int n,m;
long long f[20][1<<18];
vector<pair<int,int>> cs[25];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y,z;
        cin>>x>>y>>z;
        x--;
        y--;
        cs[x].emplace_back(y,z);
    }
    f[0][0]=1;
    for(int i=0;i<n;i++){
        for(int s=0;s<1<<n;s++)if(f[i][s]){
            static int pre[18];
            pre[0]=s&1;
            for(int j=1;j<n;j++)pre[j]=pre[j-1]+(s>>j&1);
            for(int j=0;j<n;j++)if(s>>j&1^1){
                bool can=true;
                for(pair<int,int> &p:cs[i])if(p.second<pre[p.first]+(p.first>=j)){
                    can=false;
                    break;
                }
                if(can)f[i+1][s|1<<j]+=f[i][s];
            }
        }
    }
    cout<<f[n][(1<<n)-1];

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

int main(){
  int n, t; cin >> n;
  double a, b;
  vector<double> l(n), r(n);
  for(int i = 0; i < n; ++i){
    cin >> t >> a >> b;
    if(t == 2){b -= 0.1;}
    else if(t == 3){a += 0.1;}
    else if(t == 4){a += 0.1; b -= 0.1;}
    l[i] = a; r[i] = b;
  }
  
  // for(int i = 0; i < n; ++i){cout << l[i] << " ";}cout << endl;
  // for(int i = 0; i < n; ++i){cout << r[i] << " ";}cout << endl;

  double c, d, e, f;
  int ans = 0;
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      if(i == j){continue;}
      c = l[i]; d = r[i]; e = l[j]; f = r[j];
      if(d > f){swap(c, e); swap(d, f);}
      if(d >= e){ans += 1;}
    }
  }
  cout << ans/2 << endl;  
}