def dfs(node, edges, known)
  while catch(:retry) {
          known[node] = true
          edges[node].each_with_index do |other, i|
            unless known[other]
              if i == edges[node].size - 1
                node = other
                throw :retry, true
              else
                dfs(other, edges, known)
              end
            end
          end
          false
        }
  end
end

n, m = gets.split.map(&:to_i)
table = m.times.map { gets.split.map(&:to_i) }
known = Array.new(n)
edges = Hash.new { [] }

table.each do |x, y, z|
  x -= 1
  y -= 1
  edges[x] <<= y
  edges[y] <<= x
end

cost = 0
(0...n).each do |i|
  unless known[i]
    cost +=1
    dfs(i, edges, known)
  end
end
puts cost
