import sys input = sys.stdin.buffer.readline MOD = 1000000007 class Factorial(): def __init__(self, n): self.fct = [0] * (n + 1) self.inv = [0] * (n + 1) self.fct[0] = 1 self.inv[0] = 1 for i in range(n): self.fct[i + 1] = self.fct[i] * (i + 1) % MOD self.inv[n] = pow(self.fct[n], MOD - 2, MOD) for i in range(n)[::-1]: self.inv[i] = self.inv[i + 1] * (i + 1) % MOD def fact(self, m): return self.fct[m] def invf(self, m): return self.inv[m] def perm(self, m, k): if m < k: return 0 return self.fct[m] * self.inv[m - k] % MOD def invp(self, m, k): if m < k: return 0 return self.inv[m] * self.fct[m - k] % MOD def comb(self, m, k): if m < k: return 0 return self.fct[m] * self.inv[k] * self.inv[m - k] % MOD def invc(self, m, k): if m < k: return 0 return self.inv[m] * self.fct[k] * self.fct[m - k] % MOD def hcmb(self, m, k): if m + k == 0: return 1 return self.comb(m + k - 1, k) N, M = map(int, input().split()) f = Factorial(2 * N + 1) res = 2 * N * f.comb(2 * N, N) % MOD for _ in range(M): t, x, y = map(int, input().split()) if t == 1: res -= f.comb(x + y, x) * f.comb(2 * N - x - 1 - y, N - x - 1) res %= MOD else: res -= f.comb(x + y, y) * f.comb(2 * N - y - 1 - x, N - y - 1) res %= MOD print(res)