from scipy.sparse.csgraph import dijkstra

N, M = map(int, input().split())
G = [[float('inf')]*N for i in range(N)]

for i in range(M):
    a, b, c = map(int, input().split())
    G[a-1][b-1] = c
    G[b-1][a-1] = c

distance, path = dijkstra(G, directed=False, return_predecessors=True)
K = 0
for p in path:
    K = max(K, len(set(p))-1)
print(M-K)
