#include using namespace std; #define bokusunny ios::sync_with_stdio(false), cin.tie(nullptr); #include using namespace atcoder; using mint = modint1000000007; const int MOD = 1e9 + 7; template struct ModComb { private: vector Fac, Finv, Inv; int MAX_N; public: ModComb(int max_n = 1 << 20) { MAX_N = max_n; Fac.resize(MAX_N + 1), Finv.resize(MAX_N + 1), Inv.resize(MAX_N + 1); Fac[0] = Fac[1] = 1; Finv[0] = Finv[1] = 1; Inv[1] = 1; for (int i = 2; i <= MAX_N; i++) { Fac[i] = Fac[i - 1] * i; Inv[i] = (mint)0 + MOD - Inv[MOD % i] * (MOD / i); Finv[i] = Finv[i - 1] * Inv[i]; } } T nCk(int n, int k) { assert(n <= MAX_N); if (n < k) return 0; if (n < 0 || k < 0) return 0; return Fac[n] * Finv[k] * Finv[n - k]; } T nHr(int n, int r) { return nCk(n + r - 1, r); } T nPr(int n, int r) { assert(n <= MAX_N); assert(0 <= r && r <= n); return Fac[n] / Fac[n - r]; } }; void solve() { int N, M; cin >> N >> M; vector T(M), X(M), Y(M); for (int i = 0; i < M; i++) cin >> T[i] >> X[i] >> Y[i]; ModComb Comb; mint ans = (mint)1 * 2 * N * Comb.nCk(2 * N, N); for (int i = 0; i < M; i++) { if (T[i] == 1) { ans -= Comb.nCk(X[i] + Y[i], X[i]) * Comb.nCk(2 * N - X[i] - Y[i] - 1, N - Y[i]); } else { ans -= Comb.nCk(X[i] + Y[i], X[i]) * Comb.nCk(2 * N - X[i] - Y[i] - 1, N - X[i]); } } cout << ans.val() << endl; } int main() { bokusunny; solve(); return 0; }