#include <atcoder/all>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace atcoder;
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ull MOD = 1000000007;
using mll = static_modint<1000000007>;
#define rep(i,n) for(int i=0; i<(n); i++)


vector<mll> F,I,iF;
void initComb(int Z){
  F.assign(Z+1,1);
  for(int i=1; i<=Z; i++) F[i] = F[i-1] * i;
  I.assign(Z+1,1);
  for(int i=2; i<=Z; i++) I[i] = -(I[MOD%i] * (MOD / i));
  iF.assign(Z+1,1);
  for(int i=1; i<=Z; i++) iF[i] = iF[i-1] * I[i];
}

mll Comb(int n,int r){ return F[n] * iF[r] * iF[n-r]; }

int main(){
  int N,M; cin >> N >> M;
  initComb(N+N);
  mll ans = Comb(N+N,N) * N * 2;
  rep(i,M){
    int t,x,y; cin >> t >> x >> y;
    mll d = 1;
    d *= Comb(x+y,x);
    if(t == 1) d *= Comb(N-x-1+N-y,N-y);
    if(t == 2) d *= Comb(N-x+N-y-1,N-x);
    ans -= d;
  }
  cout << ans.val() << endl;
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;