

from heapq import heappush, heappop, heapify

n, m = map(int, input().split())

#abcm = [ list( map(int,input().split()) ) for _ in range(m)]


graph = [[0]*n for _ in range(n)]

for _ in range(m):
    a, b, c = map(int, input().split())
    a-= 1;b-=1

    graph[a][b] = graph[b][a] = c

#print(graph)

# Prim's Algorithm
# https://tjkendev.github.io/procon-library/python/graph/min_st_prim.html

heap = [(c, i) for i, c in enumerate(graph[0]) if c != 0]
heapify(heap)
visited = [False]*n
visited[0] = True

from_ = 0
to_ = 0
edge = []

while heap:
    c, v = heappop(heap)

    if visited[v] :
        continue
    
    to_ = v
    edge.append( (from_,to_) )
    from_ = to_
    for i, c in enumerate(graph[v]):
        if visited[i] :
            continue
        heappush(heap, (c, i))

    visited[v] = True
        

#print(heap)

#print(edge)

print( m - len(edge) )
