N, M = map(int, input().split())
# union find?
uf = list(range(N)) # uf[i] = 1 if vertice i is connected to 1
a_arr = []
b_arr = []
c_arr = []
for _ in range(M):
    a, b, c = map(int, input().split())
    a_arr.append(min(a, b) - 1)
    b_arr.append(max(a, b) - 1)
    c_arr.append(c)
c_arr = sorted(c_arr)

ans = 0
for m in range(M):
    if uf[a_arr[m]] == uf[b_arr[m]]:
        ans += 1
    else:
        for n in range(N):
            if uf[n] == uf[b_arr[m]]:
                uf[n] = uf[a_arr[m]]
# print(uf)
print(ans)