import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
N, M = map(int, input().split())
a, b, c = [], [], []
for i in range(M):
    ai, bi, ci = map(int, input().split())
    a.append(ai-1)
    b.append(bi-1)
    c.append(ci)

G = csr_matrix((c, (a, b)), shape=(N, N), dtype=int)
D, P = floyd_warshall(G, directed=False, return_predecessors=True)
edges = []
for i in range(N):
    for j in range(N):
        if P[i][j] < 0 or i == P[i][j]:
            continue
        edges.append((min(i, P[i][j]), max(i, P[i][j])))
edges = list(set(edges))
print(M - len(edges))