import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
N,M = map(int,input().split())
start = []
goal = []
data = []
for _ in range(M):
    a,b,c = map(int,input().split())
    start.append(a)
    goal.append(b)
    data.append(c)
csr = csr_matrix((data,(start,goal)),shape=(N+1,N+1))
p,q = floyd_warshall(csr,directed=False,return_predecessors=True)
d=[[True]*N for _ in range(N)]
for i in range(1,N+1):
    for k,v in enumerate(q[i]):
        if v != -9999:
            d[i-1][v-1]=False
            d[v-1][i-1]=False
print(sum([sum(i) for i in d])//2)