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*1000+b] = c
  cost[b*1000+a] = c
  tagged[a*1000+b] = 0
  
for a,lst in edges.items():
  min_val = min([cost[a*1000 + b] for b in lst])
  for b in lst:
    if cost[a*1000+b] == min_val:
      if a*1000+b in tagged:
        tagged[a*1000+b] = 1
      elif b*1000+a in tagged:
        tagged[b*1000+a] = 1


ans = len([v for k,v in tagged.items() if v == 0])
print(ans)