N,M=map(int,input().split()) INF=10**18 D=[[INF]*N for i in range(N)] for i in range(N): D[i][i]=0 for i in range(M): s,t,d=map(int,input().split()) D[s-1][t-1]=min(D[s-1][t-1],d) for k in range(N*5): k%=N for i in range(N): for j in range(N): D[i][j]=min(D[i][j],D[i][k]+D[k][j]) P=0 for i in range(N): for j in range(N): if D[i][j]