def main():
    N, M = map(int,input().split())
    prm = [[1001 for _ in range(N)] for _ in range(N)]
    d = [tuple(map(int,input().split())) for _ in range(M)]
    min_path = 1001 * N
    for a,b,c in d:
        prm[a-1][b-1] = c
    for i in range(N):
        for j in range(N):
            if i == j:
                prm[i][j] = 0
                continue
            if prm[i][j] < prm[j][i]:
                prm[j][i] = prm[i][j]
            else:
                prm[i][j] = prm[j][i]
        tmp =sum(prm[i])
        if tmp < min_path:
            min_path = tmp
    res = 0
    for a,b,c in d:
        if min_path < c:
            res +=1
    print(res)

if __name__ == '__main__':
    main()