import heapq

N, M = map(int, input().split())
graph = {i:[] for i in range(1, N+1)}
visited = [False for i in range(N+1)]
cost = [10**20 for i in range(N+1)]
ans = 0

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

q = []
for r in graph[1]:
    heapq.heappush(q, r)
    
visited[1] = True    
cost[1] = 0

while q:
    c, r = heapq.heappop(q)    
    if not visited[r]:
        cost[r] = c
        visited[r] = True
        ans += 1
        
        for c_, r_ in graph[r]:
            if not visited[r_]:
                heapq.heappush(q, (c+c_, r_))
        
print(M-ans)