#pragma GCC optimize("Ofast", "unroll-loops") #include using namespace std; using ll = long long; constexpr ll mod = 1000000007LL; ll modpow(ll a, ll b) { if (a > mod) a %= mod; if (b == 0LL) return 1LL; ll tmp = modpow(a, b / 2); if (b & 1LL) return tmp * tmp % mod * a % mod; return tmp * tmp % mod; } ll inverse(ll a) { return modpow(a, mod - 2); } ll fact(ll k, bool inverse = false) { static vector fac(2, 1LL); static vector inv(2, 1LL); static vector finv(2, 1LL); static ll nx = 2LL; while (nx <= k) { fac.push_back(fac[nx - 1] * nx % mod); inv.push_back(mod - inv[mod % nx] * (mod / nx) % mod); finv.push_back(finv[nx - 1] * inv[nx] % mod); ++nx; } if (!inverse) return fac[k]; return finv[k]; } ll comb(ll a, ll b) { if (b < 0 || b > a) return 0; return fact(a) * fact(b, 1) % mod * fact(a - b, 1) % mod; } int main(void){ int N, M; cin >> N >> M; ll ans = 2LL * N * comb(2 * N, N) % mod; for (int _ = 0; _ < M; ++_){ int t, x, y; cin >> t >> x >> y; ll sub; if (t == 1){ sub = comb(x + y, x) * comb(2 * N - x - y - 1, N - y) % mod; } else { sub = comb(x + y, x) * comb(2 * N - x - y - 1, N - x) % mod; } ans -= sub; if (ans < 0) ans += mod; } cout << ans << endl; return 0; }