import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) mod = 10 ** 9 + 7 class Combination: """ SIZEが10**6程度以下の二項係数を何回も呼び出したいときに使う 使い方: comb = Combination(SIZE, MOD) comb(10, 3) => 120 """ def __init__(self, N, MOD=10 ** 9 + 7): self.MOD = MOD self.__make_factorial_list(N) def __call__(self, n, k): if k < 0 or k > n: return 0 res = self.fact[n] * self.inv[k] % self.MOD res = res * self.inv[n - k] % self.MOD return res def nPk(self, n, k): if k < 0 or k > n: return 0 return self.fact[n] * self.inv[n - k] % self.MOD def nHk(self, n, k): if k == 0: return 1 return self.__call__(n + k - 1, k) def __make_factorial_list(self, N): self.fact = [1] * (N + 1) self.inv = [1] * (N + 1) MOD = self.MOD for i in range(1, N + 1): self.fact[i] = (self.fact[i - 1] * i) % MOD self.inv[N] = pow(self.fact[N], MOD - 2, MOD) for i in range(N, 0, -1): self.inv[i - 1] = (self.inv[i] * i) % MOD return N, M = map(int, input().split()) comb = Combination(N+N+100, mod) ans = 2 * N * comb(2 * N, N) % mod for _ in range(M): T, X, Y = map(int, input().split()) a_to_m = comb(X + Y, X) if T == 1: X += 1 else: Y += 1 m_to_b = comb(2 * N - X - Y, N - X) ans -= a_to_m * m_to_b % mod ans %= mod print(ans)