import sys
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
from itertools import combinations
read = sys.stdin.read

N, M, *abc = map(int, read().split())
a, b, c = zip(*zip(*[iter(abc)] * 3))

graph = csr_matrix((c, (a, b)), shape=(N + 1, N + 1))
distance = shortest_path(graph, directed=False)

answer = 0

for i, j in zip(a, b):
    for s in range(1, N + 1):
        if distance[i][j] + distance[j][s] == distance[i][s]:
            continue

        if distance[j][i] + distance[i][s] == distance[j][s]:
            continue

        answer += 1

print(answer)