# frozen_string_literal: true def solve A.select { _1 > 0 }.sort { _2 <=> _1 }.take(K).sum end _, K = gets.split.map(&:to_i) A = gets.split.map(&:to_i) puts solve