N, M = map(int, input().split())
link = [[] for _ in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    link[a-1].append([b-1, c])
    link[b-1].append([a-1, c])
visited = [[0] * 2 for _ in range(N)]

def dfs(v, d, cnt, pv):
    if visited[v][0]:
        return
    visited[v][0] = 1
    for nv in link[v]:
        t = nv[0]
        if t == pv:
            continue
        d += nv[1]
        if visited[t][1] == 0:
            visited[t][1] = d
            visited[v][1] = d
        else:
            if visited[t][1] < d:
                cnt += 1
            elif visited[t][1] == d:
                pass
            elif visited[t][1] > d:
                cnt += 1
                visited[t][1] = d
                visited[v][1] = d
        dfs(t, d, cnt, v)
    return cnt

ans = dfs(0, 0, 0, -1)

print(ans)
