STACK_SIZE = 64*1024*1024
if ENV['RUBY_THREAD_VM_STACK_SIZE'].to_i < STACK_SIZE
  ENV['RUBY_THREAD_VM_STACK_SIZE'] = STACK_SIZE.to_s
  exec("ruby2.3 --disable-gems ./Main.rb")
end

def dfs(node, edges, known)
  known[node] = true
  edges[node].each do |other|
    unless known[other]
      dfs(other, edges, known)
    end
  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
