import sys INF = float('inf') #10**20,2**63,float('inf') MOD = 10**9 + 7 MOD2 = 998244353 #from collections import defaultdict def solve(): def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LC(): return list(input()) def IC(): return [int(c) for c in input()] def MI(): return map(int, sys.stdin.readline().split()) N,M = MI() def modinv(x): return pow(x, MOD - 2, MOD) MAX = 500050 Fact = [0]*MAX Fact[0] = 1 Fact[1] = 1 for n in range(2,MAX): Fact[n] = (n*(Fact[n-1]))%MOD #print((Fact[N+K]*modinv(Fact[N]*Fact[K])) % MOD) All = Fact[2*N]*modinv(Fact[N]*Fact[N]) % MOD All *= (2*N) All %= MOD #print(All) for _ in range(M): T,X,Y = MI() Bef = Fact[X+Y]*modinv(Fact[X]*Fact[Y])%MOD Up = N-X Right = N-Y if T==1: #print(Fact[(Up-1)+Right]*modinv(Fact[Up-1]*Fact[Right]) % MOD) Tmp = (Fact[(Up-1)+Right]*modinv(Fact[Up-1]*Fact[Right]))%MOD All-= Bef*Tmp All %= MOD else: #print(Fact[Up+ Right-1] * modinv(Fact[Up] * Fact[Right-1]) % MOD) Tmp = (Fact[Up+ Right-1] * modinv(Fact[Up] * Fact[Right-1]))%MOD All -= Bef*Tmp All %= MOD print(All) return solve() #sys.setrecursionlimit(10 ** 6)#再帰関数ではコメントにしないこと!!