require 'set'
require 'securerandom'

N, M = gets.chomp.split(' ').map(&:to_i)
xyzes = M.times.map { gets.chomp.split(' ').map(&:to_i) }

all = N.times.map { |n| [n, nil] }.to_h

xyzes.each do |a, b, _|
  if all[a] || all[b]
    all[a] = all[b] = all[a] || all[b]
  else
    all[a] = all[b] = SecureRandom.uuid
  end
end

groups = all.values.select(&:itself)
puts (N - groups.size) + groups.uniq.size