#include using namespace std; typedef long long ll; typedef unsigned long long ull; const ll mod = 1000000007; vector factorial; ll powmod(ll n,int m){ if(n==0) return 0; if(m==0 || n==1) return 1; if(m%2) return powmod(n*n %mod, m/2) *n %mod; else return powmod(n*n %mod, m/2); } ll comb(int n,int m){ if(m>n || m<0) return 0; m = min(n-m,m); if(m==0) return 1; ll mul = factorial[n], div = factorial[m] * factorial[n-m] %mod; return mul * powmod(div,mod-2) %mod; } int main(){ int n,m; cin >> n >> m; factorial.resize(2*n+1,1); for(int i=1; i<=2*n; ++i) { factorial[i]= factorial[i-1] * i % mod; } ll ans = comb(2*n,n) * 2*n %mod; ll minus = 0; for(int i=0; i> t >> x >> y; //cout << x << ' ' << y << endl; //cout << comb(x+y,x) << ' ' << comb(2*n-x-y-1, t==1 ? n-y : n-x) << endl; minus += (ll)comb(x+y,x) * comb(2*n-x-y-1, t==1 ? n-y : n-x) %mod; minus %= mod; } cout << (ans + mod - minus) % mod << endl; }