import heapq N,M = map(int, input().split()) G = {i:[] for i in range(1,N+1)} for _ in range(M): s,t,d = map(int, input().split()) G[s].append((t,d)) INFTY = 10**15 for i in range(1,N+1): dist = [INFTY]*(N+1) visited = [False]*(N+1) dist[i] = 0 heap = [(0,i)] while heap: d,i = heapq.heappop(heap) if dist[i] < d:continue visited[i] = True for j,c in G[i]: if not visited[j] and dist[j]>d+c: dist[j] = d+c heapq.heappush(heap,(d+c,j)) ans = 0 for j in range(1,N+1): if dist[j]