""" """ from sys import stdin def modfac(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return factorials, invs def modnCr(n,r): return fac[n] * inv[n-r] * inv[r] % mod mod = 10**9+7 fac,inv = modfac(500000,mod) N,M = map(int,stdin.readline().split()) ans = modnCr(2*N,N) * (2*N) for i in range(M): t,x,y = map(int,stdin.readline().split()) if t == 1: ans -= modnCr(x+y,x) * modnCr((N-x-1)+(N-y),N-x-1) else: ans -= modnCr(x+y,x) * modnCr((N-x)+(N-y-1),N-x) ans %= mod print (ans)