class UnionFind
  attr :union_count

  def initialize()
    @table = Hash.new { |_hash, key| key }
    @rank = Hash.new { 0 }
    @union_count = 0
  end

  def find(elt)
    if @table[elt].eql? elt
      elt
    else
      @table[elt] = find(@table[elt])
    end
  end
 
  def union(node1, node2)
    root1 = find(node1)
    root2 = find(node2)

    if @rank[root1] < @rank[root2]
      @table[root1] = root2
    elsif @rank[root1] > @rank[root2]
      @table[root2] = root1
    elsif root1 != root2
      @table[root2] = root1
      @rank[root1] += 1
    else
      return
    end
    @union_count += 1
  end

end

n, m = gets.split.map(&:to_i)

uf = UnionFind.new

m.times do
  x, y, z = gets.split.map(&:to_i)
  uf.union(x, y)
end

puts n - uf.union_count
