from collections import Counter N,M=map(int,input().split()) C=Counter() for i in range(M): a,b,c=map(int,input().split()) C[a,b]=c DP=[0]*(1<