N, M = gets.split.map(&:to_i)
U = Array.new(N + 1, &:itself)

class << U
  def root(i)
    self[i] == i ? i : root(self[i]).tap{|j| self[i] = j}
  end
  def union(i,j)
    pi = root(i)
    pj = root(j)
    self[pi] = pj if pi != pj
  end
end

F = M.times.map{ gets.split.map(&:to_i) }
F.each do |i,j,z|
  U.union(i, j)
end

puts (1 .. N).group_by{|i| U.root(i) }.size
