(defn input []
  (->> (repeatedly 2 read-line)
    (map (comp
           (partial map #(Integer/parseInt %))
           #(clojure.string/split % #"\s")))))

(defn Snake-Toy [[[N K] L]]
  ((comp
     (partial reduce +)
     (partial take-last K)
     sort)
   L))

(-> (input)
  Snake-Toy
  println)