n,m = gets.split.map(&:to_i)
class UnionFind
  def initialize(size)
    @rank = Array.new(size,0)
    @parent = Array.new(size,&:itself)
  end
  def getRoot(x)
    @parent[x] == x ? x : (@parent[x] = getRoot(@parent[x]))
  end
  def unite(x,y)
    xp = getRoot(x)
    yp = getRoot(y)
    if xp == yp
      return
    elsif @rank[xp] > @rank[yp]
      @parent[yp] = xp
    else
      @parent[xp] = yp
      @rank[yp] += 1 if @rank[xp] = @rank[yp]
    end
  end
  def same?(x,y)
    getRoot(x) == getRoot(y)
  end
  def size
    @parent.map{|x| getRoot(x)}.uniq.size
  end
end
g = UnionFind.new(n)
m.times do
  x,y,z = gets.split.map(&:to_i)
  g.unite(x-1,y-1) if not g.same?(x-1,y-1)
end
puts g.size