def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fac[n]*finv[r]*finv[n-r]%p def perm(n,r,p): if (r < 0) or (n < r): return 0 return fac[n]*finv[n-r]%p NN = 220000 MOD = pow(10,9) + 7 fac = [-1]*(NN+1); fac[0] = 1; fac[1] = 1 #階乗 finv = [-1]*(NN+1); finv[0] = 1; finv[1] = 1 #階乗の逆元 inv = [-1]*(NN+1); inv[0] = 0; inv[1] = 1 #逆元 for i in range(2,NN+1): fac[i] = fac[i-1]*i%MOD inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD finv[i] = finv[i-1]*inv[i]%MOD def main(): N,M = map(int,input().split()) G = [[[1,1] for _ in range(N+1)] for _ in range(N+1)] for _ in range(M): t,x,y = map(int,input().split()) if t == 1: G[x][y][0] = 0 else: G[x][y][1] = 0 ans = 0 for i in range(N+1): for j in range(N+1): #右移動 if i != N and G[i][j][0] != 0: right = cmb(i+j,i,MOD)*cmb(N-(i+1)+N-j,N-j,MOD) #print("migi",(i,j),right) ans += right%MOD #上移動 if j != N and G[i][j][1] != 0: up = cmb(i+j,i,MOD)*cmb(N-i+N-(j+1),N-i,MOD) #print("ue",(i,j),up) ans += up%MOD ans %= MOD print(ans) if __name__ == '__main__': main()