from heapq import *
import numpy as np

def dijkstra(start,node,edge):
    #始点sから各頂点への最短距離
    #node:頂点数
    #d:各頂点へのコスト(存在しないときはinf)
    d = [float("inf")] * node
    d[start] = 0
    q = [(0,start)]
    
    while(len(q) != 0):
      ci,i = heappop(q)
      if(d[i] < ci):
        continue
      for cj,j in edge[i]:
        if(d[j] > d[i] + cj):
          d[j] = d[i] + cj
          used[i][j] = 1
          heappush(q,(d[j], j))
    return d
  
N,M = (int(x) for x in input().split())
E = [[] for _ in [0]*N]
used = np.zeros((N,N))

for i in range(M):
  a,b,c = (int(x) for x in input().split())
  E[a-1].append((c,b-1))

d = dijkstra(0, N, E)

print(int(M - np.sum(used)))