import sys MOD = 10**9 + 7 def mul(a, b): return ((a % MOD) * (b % MOD)) % MOD def div(a, b): return mul(a, pow(b, MOD-2, MOD)) def div2(a, b): return mul(a, modinv(b)) def modinv(a): b, u, v = MOD, 1, 0 while b: t = a//b a, u = a-t*b, u-t*v a, b, u, v = b, a, v, u u %= MOD return u def frac(limit): frac = [1]*limit for i in range(2,limit): frac[i] = i * frac[i-1]%MOD fraci = [None]*limit fraci[-1] = pow(frac[-1], MOD -2, MOD) for i in range(-2, -limit-1, -1): fraci[i] = fraci[i+1] * (limit + i + 1) % MOD return frac, fraci frac, fraci = frac(1341398) def cmb(a, b): if not a >= b >= 0: return 0 return frac[a]*fraci[b]*fraci[a-b]%MOD N, M = map(int, input().split()) R=cmb(2*N,N) R=R*(2*N)%MOD #print(R) for _ in range(M): t, x, y = map(int, input().split()) if t == 1: R -= cmb(x+y,x)*cmb(2*N-x-y-1, N-y) R %= MOD else: R -= cmb(x+y,x)*cmb(2*N-x-y-1, N-x) R %= MOD print(R)