#include #include using namespace std; using namespace atcoder; typedef long long ll; typedef pair P; typedef modint1000000007 mint; #define rep(i,a,b) for(ll i=a;i=b;i--) const ll inf=1e18; struct combination { vector fact, ifact; combination(int n):fact(n+1),ifact(n+1) { fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } } comb(500005); ll n,m; ll t,x,y; mint ans; int main(void){ cin.tie(0); ios::sync_with_stdio(0); cin>>n>>m; ans=2*mint(n)*comb(2*n,n); rep(i,0,m){ cin>>t>>x>>y; if(t==1){ ans-=comb(x+y,x)*comb(n*2-(x+y)-1,n-y); }else{ ans-=comb(x+y,x)*comb(n*2-(x+y)-1,n-x); } } cout<