#include using namespace std; using ll = long long; using ld = long double; using vl = vector; template using vc = vector; template using vvc = vector>; #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n)-1; i >= 0; i--) #define repe(i, l, r) for (ll i = (l); i < (r); i++) #define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--) #define repa(i,n) for (auto& i: n) template inline bool chmax(T1 &a, const T2 &b) {if (a inline bool chmin(T1 &a, const T2 &b) {if (b void verr(const set &st) { repa(a, st) cerr << a << " "; cerr << endl; } template void verr(const map &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; } template void verr(const vector>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; } template void verr(const vector& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; } ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; } template void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward(t)...); } #endif const ll INF = 4e18; const ld EPS = 1e-11; const ld PI = acos(-1.0L); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; //--------------------------------------------------------------------------------// ll modpow(ll a, ll n, ll mod_) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod_; a = a * a % mod_; n >>= 1; } return res; } const ll MAX_SIZE = 400005; array fac, inv, finv; struct finit{ finit(){ // combination init fac[0] = 1; for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % MOD; finv[MAX_SIZE - 1] = modpow(fac[MAX_SIZE - 1], MOD - 2, MOD); for(ll i = MAX_SIZE - 1; i > 0; i--) finv[i - 1] = finv[i] * i % MOD; //inv init repe(i, 1, MAX_SIZE) inv[i] = modpow(i, MOD - 2, MOD); } } finit_; ll perm(ll a, ll b) { return fac[a] * finv[a - b] % MOD; } ll comb(ll a, ll b) { return fac[a] * finv[b] % MOD * finv[a - b] % MOD; } int main() { ll N, M; cin >> N >> M; ll ans = comb(2 * N, N) * 2 * N % MOD; rep(i, M){ ll t, x, y; cin >> t >> x >> y; if(t == 1){ (ans -= comb(x + y, x) * comb(N - x - 1 + N - y, N - y)) %= MOD; }else{ (ans -= comb(x + y, x) * comb(N - x - 1 + N - y, N - y - 1)) %= MOD; } } cout << (ans + MOD) % MOD << endl; }