# 最小全域木

import sys
readline = sys.stdin.readline

import networkx as nx

N,M = map(int,readline().split())
INF = 10 ** 9
G = nx.Graph()
for i in range(M):
  a,b,c = map(int,readline().split())
  G.add_edge(a-1,b-1,weight = c)
  
T = nx.minimum_spanning_tree(G)
print(M - len(T.edges()))
