n, m = map(int, input().split())
joined = [0] * n

from heapq import heappop, heappush
E = []
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    heappush(E, (c, a, b))

ans = 0
for _ in range(m):
    c, a, b = heappop(E)

    if joined[a] == 1 and joined[b] == 1:
        ans += 1
    else:
        joined[a] = 1
        joined[b] = 1
print(ans)
