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

    stack = []
    stack.push(i)
    until stack.empty?
      node = stack.pop
      next if known[node]
      known[node] = true
      edges[node].each do |other|
        unless known[other]
          stack.push(other)
        end
      end
    end
  end
end
puts cost
