from collections import defaultdict
from heapq import heappop, heappush


N, M = map(int, input().split())


class Graph(object):
    def __init__(self):
        self.graph = defaultdict(dict)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src][dst] = weight

    def get_nodes(self):
        return self.graph.keys()


class Prim(object):

    def __init__(self, graph, start=0):
        self.edge = []
        self.total = 0

        g = graph.graph
        n = len(graph)
        visited = [False] * n
        visited[start] = True

        Q = []
        for v, cost in g[start].items():
            heappush(Q, (cost, (start, v)))

        while Q:
            cost, edge = heappop(Q)

            if visited[edge[1]]:
                continue

            self.edge.append(edge)
            self.total += cost
            visited[edge[1]] = True

            for v, cost in g[edge[1]].items():
                heappush(Q, (cost, (edge[1], v)))



g = Graph()
for _ in range(M):
    a, b, c = map(int, input().split())
    g.add_edge(a - 1, b - 1, c)
    g.add_edge(b - 1, a - 1, c)
print(M - len(Prim(g).edge))