N, M = gets.split.map &:to_i
G = Array.new(N){Array.new}
M.times do
  x, y, z = gets.split.map &:to_i
  x -= 1
  y -= 1
  G[x] << y
  G[y] << x
end

res = 0
used = Array.new(N)
N.times do |r|
  next if used[r]
  used[r] = true
  res += 1
  q = [r]
  until q.empty?
    u = q.shift
    G[u].each do |v|
      next if used[v]
      used[v] = true
      q << v
    end
  end
end
p res
