class CP: def __init__(self, N): self.fact = [1] self.fact_inv = [1] for i in range(1, N+1): self.fact.append((self.fact[-1]*i)%MOD) self.fact_inv.append(pow(self.fact[-1], -1, MOD)) def C(self, N, K): if N >= K: return self.fact[N]*self.fact_inv[K]%MOD*self.fact_inv[N-K]%MOD else: return 0 def P(self, N, K): if N >= K: return self.fact[N]*self.fact_inv[N-K]%MOD else: return 0 N, M = map(int, input().split()) free = [list(map(int, input().split())) for _ in range(M)] MOD = 10**9+7 cp = CP(10**5*4) ans = cp.C(N*2, N)*(N*2) for t, x, y in free: if t == 1: nx, ny = N-x-1, N-y else: nx, ny = N-x, N-y-1 ans -= cp.C(x+y, x)*cp.C(nx+ny, nx)%MOD ans %= MOD print(ans)