N,M = map(int,input().split()) mod = 10**9 + 7 kaijou = [1] kaijou_ = [1] for i in range(1,2*N+1): k = kaijou[-1] * i k %= mod kaijou.append(k) k = pow(k,-1,mod) kaijou_.append(k) def comb(n,r): res = kaijou_[n-r] * kaijou_[r] res %= mod res *= kaijou[n] res %= mod return res ans = comb(2*N,N) * (2*N) ans %= mod for _ in range(M): t,x,y = map(int,input().split()) xx,yy = N - x,N - y if t == 1: xx -= 1 else: yy -= 1 res = comb(x+y,x) * comb(xx+yy,xx) res %= mod ans -= res ans %= mod print(ans)