#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

template<class T>
vector<T> make_vec(size_t a){
	return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
	return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin>>N>>M;
    vi X(M),Y(M),Z(M);
    rep(i,M) cin>>X[i]>>Y[i]>>Z[i];

    vll dp(1<<N);
    dp[0] = 1;
    rep(S,1<<N){
        int popcnt = __builtin_popcount(S);
        bool ok=true;
        rep(i,M){
            if (popcnt>X[i]) continue;
            int mask = (1<<Y[i])-1;
            if (__builtin_popcount(S&mask) > Z[i]){
                ok=false;
                break;
            }
        }
        if (!ok) continue;
        rep(i,N)if(!(S>>i&1)){
            int T = S|(1<<i);
            dp[T] += dp[S];
        }
    }
    cout<<dp[(1<<N)-1]<<endl;
    return 0;
}

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

#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ff first
#define ss second
#define YES printf("YES\n")
#define NO printf("NO\n")
#define nn "\n"
#define sci(x) scanf("%d", &x)
#define LL_INF (1LL << 62)
#define INF (1 << 30)
#define SetBit(x, k) (x |= (1LL << k))
#define ClearBit(x, k) (x &= ~(1LL << k))
#define CheckBit(x, k) (x & (1LL << k))
#define mod 1000000007 
#define N 300005

int n, q;
int arr[N];

int tree[3*N];

void init(int b, int e, int node = 1)
{
  if (b == e)
  {
    tree[node] = arr[b];
    return;
  }
  int left = node * 2;
  int right = node * 2 + 1;
  int mid = (b + e) / 2;
  init(b, mid, left);
  init(mid + 1, e, right);
  tree[node] = tree[left] ^ tree[right];
}

int query(int b, int e, int i, int j, int node = 1)
{
  if (b >= i && e <= j)
    return tree[node];
  if (b > j || e < i)
    return 0;
  int left = node * 2;
  int right = node * 2 + 1;
  int mid = (b + e) / 2;
  return query(b, mid, i, j, left) ^ query(mid + 1, e, i, j, right);
}

void update(int b, int e, int i, int val, int node = 1)
{
  if (b > i || e < i)
    return;
  if (b == e && e == i)
  {
    tree[node] = val;
    return;
  }
  int left = node * 2;
  int right = node * 2 + 1;
  int mid = (b + e) / 2;
  update(b, mid, i, val, left);
  update(mid + 1, e, i, val, right);
  tree[node] = tree[left] ^ tree[right];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
    }

    init(1, n);

    while(q--){
        int t, x, y;
        cin >> t >> x >> y;
        if(t==1){
            update(1, n, x, y^query(1, n, x, x));
        }
        else {
            cout << query(1, n, x, y) << nn;
        }
    }


 
    return 0;
}
 
