from itertools import permutations N,M = map(int,input().split()) A = [list(map(int,input().split())) for _ in range(M)] ans = 0 for P in permutations(range(N)): Ind = [0]*N for i in range(N): Ind[P[i]] = i cnt = 0 for j in range(M): a,b,c = A[j] if Ind[a]