class UnionFind
  def initialize(n)
    @par = n.times.to_a
  end

  def root(x)
    return x if @par[x] == x
    root(@par[x])
  end

  def unite(x, y)
    rx = root(x)
    ry = root(y)
    return if rx == ry
    @par[rx] = ry 
  end

  def count_tree()
    @par.map.with_index { |e, i| e == i ? 1 : 0}.reduce(&:+)
  end
end

N, M = gets.split(' ').map(&:to_i)
uf = UnionFind.new(N)

M.times do
  x, y, z = gets.split(' ').map{ |n| n.to_i - 1 }
  uf.unite(x, y)
end
puts uf.count_tree()
