N, K = gets.split.map(&:to_i) A = gets.split.map(&:to_i) if A.all? { |a| a < 0 } puts A.sort.last else puts A.sort.pop(K).select(&:positive?).sum end