import heapq
n, m = map(int, input().split())
ans = [1 for _ in range(m)]
done = [True for _ in range(n)]
graph = [set() for _ in range(n)]
side = dict()
ans = [0 for _ in range(m + 1)]
for i in range(m):
    a, b, c = map(int, input().split())
    t = (a - 1, b - 1, c)
    side[i] = t
    graph[a-1].add(i)
    graph[b-1].add(i)

D = [(0, 0, m), ]
heapq.heapify(D)

while D:
    d = heapq.heappop(D)
    if done[d[1]]:
        done[d[1]] = False
        ans[d[2]] = 1

        for i in graph[d[1]]:
            a, b, c = side[i]
            if b == d[1]:
                a, b = b, a
            if done[b]:
                heapq.heappush(D, (d[0] + c, b, i))

print(m - (sum(ans) - 1))
