#include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using pll = std::pair; #define rep(i, n) for (long long i = 0LL; i < (long long)(n); i++) #define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++) #define repr(i, n) for (long long i = (long long)(n) - 1; i >= 0LL; i--) #define repr2(i, n, s) for (long long i = (long long)(n) - 1; i >= (long long)(s); i--) #define nCr(n, r) ((n) >= (r) ? fac.at(n) * inv_fac.at(r) * inv_fac.at((n) - (r)) : 0) template bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; } template bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; } const long long INF = 2e18; using mint = modint1000000007; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); vector fac(1'000'000 + 1, 1), inv_fac(1'000'000 + 1, 1); rep2(i_, 2, 1'000'000 + 1) { fac[i_] = i_ * fac[i_ - 1]; inv_fac[i_] = fac[i_].inv(); } ll N, M; cin >> N >> M; mint ans = 2 * N * nCr(2 * N, N); rep(i, M) { ll t, x, y; cin >> t >> x >> y; if (t == 1) { ans -= nCr(x + y, x) * nCr(2 * N - (x + y + 1), N - y); } else { ans -= nCr(x + y, x) * nCr(2 * N - (x + y + 1), N - x); } } cout << ans.val() << "\n"; }