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

class << U
  def root(i)
    self[i] == i ? i : (self[i] = root(self[i]))
  end
  
  def union(i,j)
    pi = root(i)
    pj = root(j)
    self[i] = self[j] = (pi < pj ? 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


