#include using namespace std; typedef long long ll; const int P=1000000007; int mpow(int x,int n){ if(n==1)return x; ll half=mpow(x,n/2),ret=half*half%P; if(n%2)ret=ret*x%P; return ret; } int inv(int x){ return mpow(x,P-2); } int fac(int n){ vector cache{1}; while(cache.size()<=n) cache.push_back(1ll*cache.back()*cache.size()%P); return cache[n]; } int ifac(int n){ vector cache{1}; while(cache.size()<=n) cache.push_back(1ll*cache.back()*inv(cache.size())%P); return cache[n]; } int binom(int n,int m){ return 1ll*fac(n)*ifac(m)%P*ifac(n-m)%P; } int main(){ int n,m; cin>>n>>m; int ans=0; for(int i=0;i>t>>x0>>y0; int x1=x0,y1=y0; if(t==1)x1++; else y1++; ans+=1ll*binom(x0+y0,x0)*binom(n*2-x1-y1,n-x1)%P; if(ans>=P)ans-=P; } ans=1ll*binom(n*2,n)*n*2%P-ans; if(ans<0)ans+=P; cout<