import sys input=lambda:sys.stdin.readline().rstrip() mod=pow(10,9)+7 ran=400001 fact=[1 for i in range(ran)] inv=[1 for i in range(ran)] for i in range(2,ran): fact[i]=(fact[i-1]*i)%mod rem=mod-2 temp=fact[ran-1] while rem: if rem%2: inv[ran-1]=(inv[ran-1]*temp)%mod temp=(temp*temp)%mod rem//=2 for i in range(ran-2,-1,-1): inv[i]=(inv[i+1]*(i+1))%mod def calc(a,b): return (fact[a+b]*inv[a]*inv[b])%mod N,M=map(int,input().split()) ans=(calc(N,N)*2*N)%mod for i in range(M): t,x,y=map(int,input().split()) ans=(ans-calc(x,y)*calc(N-x-(t==1),N-y-(t==2)))%mod print(ans)