N,M = map(int,input().split()) P = 10 ** 9 + 7 C = N + N + 3 fact = [1] * C fact_inv = [1] * C for i in range(2,C): fact[i] = fact[i-1] * i % P fact_inv[-1] = pow(fact[-1],P-2,P) for i in range(C-2,0,-1): fact_inv[i] = fact_inv[i+1] * (i + 1) % P def comb(n,k): return fact[n] * fact_inv[k] * fact_inv[n-k] % P ans = comb(N + N,N) * (N + N) % P for _ in range(M): t,x,y = map(int,input().split()) if t == 1: tmp = comb(x+y,x) * comb(N-x-1+N-y,N-y) % P ans = (ans - tmp) % P else: tmp = comb(x+y,x) * comb(N - x + N - y - 1,N - x) % P ans = (ans - tmp) % P print(ans)