N, M = gets.chomp.split(" ").map(&:to_i);
P = []
(N + 1).times{|i| P << []}
M.times{|i|
  x, y, z = gets.chomp.split(" ").map(&:to_i);
  P[x] << y
  P[y] << x
}

C = Array.new(N + 1, 0)

cnt = 0
(1..N).each{|i|
  next if C[i] != 0
  q = []
  q.push(i)
  cnt += 1
  while(q.size > 0) do
    j = q.shift
    C[j] = 1
    P[j].select{|k| C[k] == 0}.each{|l| q.push(l)}
  end
}

puts cnt
