#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //eolibraries #define lnf 3999999999999999999 #define inf 999999999 #define fi first #define se second #define pb push_back #define ll long long #define ld long double #define all(c) (c).begin(),(c).end() #define sz(c) (int)(c).size() #define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end()) #define pii pair #define rep(i,n) for(int i = 0 ; i < n ; i++) #define drep(i,n) for(int i = n-1 ; i >= 0 ; i--) #define crep(i,x,n) for(int i = x ; i < n ; i++) #define vi vector #define vec(...) vector<__VA_ARGS__> #define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); //eodefine using namespace std; const int max_n = 2000005; //snuke's modular int template struct modularint{ ll x; modularint(ll x=0):x(x%mod){} modularint& operator+=(const modularint a){ if ((x += a.x) >= mod) x -= mod; return *this; } modularint& operator-=(const modularint a){ if ((x += mod-a.x) >= mod) x -= mod; return *this; } modularint& operator*=(const modularint a){ (x *= a.x) %= mod; return *this; } modularint operator+(const modularint a)const{ modularint res(*this); return res+=a; } modularint operator-(const modularint a)const{ modularint res(*this); return res-=a; } modularint operator*(const modularint a)const{ modularint res(*this); return res*=a; } modularint pow(int n)const{ modularint res=1,x(*this); while(n){ if(n&1)res*=x; x*=x; n>>=1; } return res; } modularint inv()const{ return pow(mod-2); } }; using mint = modularint<1000000007>; mint fact[max_n+10]; void prefact(int nupto){ fact[0]=fact[1]=1; crep(i,2,nupto) fact[i]=fact[i-1]*i; } mint cnk(int k,int n){ if(k>n) return 0; return fact[n] * (fact[k]*fact[n-k]).inv(); } int main(){ fcin; prefact(max_n); int n,m; cin>>n>>m; vec(vi) a(m,vi(3)); rep(i,m){ rep(t,3) cin>>a[i][t]; } mint ans=cnk(n,2*n); ans=ans*2*n; rep(i,m){ if(a[i][0]==1){ int e=n-a[i][1]-1; int u=n-a[i][2]; int ed=a[i][1]; int ud=a[i][2]; ans -= cnk(u,e+u)*cnk(ed,ed+ud); }else{ int e=n-a[i][1]; int u=n-a[i][2]-1; int ed=a[i][1]; int ud=a[i][2]; ans -= cnk(u,e+u)*cnk(ed,ed+ud); } } cout<