n,m=map(int,input().split()) M=1000000007 fa=[1] for i in range(1,n+n+1): fa+=[fa[-1]*i%M] a=fa[n+n]*pow(fa[n],M-2,M)*pow(fa[n],M-2,M)*(n+n)%M for i in range(m): t,x,y=map(int,input().split()) a-=fa[x+y]*pow(fa[x],M-2,M)*pow(fa[y],M-2,M)*fa[n-x-(t==1)+n-y-(t==2)]*pow(fa[n-x-(t==1)],M-2,M)*pow(fa[n-y-(t==2)],M-2,M) a%=M print(a)