N, M = [int(a) for a in input().split()]

edges = {i:[] for i in range(1,N+1)}

cost = {}
tagged = {}
for i in range(M):
  a,b,c = [int(k) for k in input().split()]
  edges[a].append(b)
  edges[b].append(a)
  cost[a*100+b] = c
  cost[b*100+a] = c
  tagged[a*100+b] = 0
  
for a,lst in edges.items():
  min_val = min([cost[a*100 + i] for i in lst])
  for b in lst:
    if cost[a*100+b] == min_val:
      if a*100+b in tagged:
        tagged[a*100+b] = 1
      elif b*100+a in tagged:
        tagged[b*100+a] = 1


ans = M - sum([v for k,v in tagged.items()])
print(ans)

