open Printf
open Scanf

let mix_juice n k p_list =
  let sort_p_list = List.sort compare p_list in
  let sort_p_list_to_k = List.init k (fun i -> List.nth sort_p_list i) in
  List.fold_right (+) sort_p_list_to_k 0

let n, k = sscanf (read_line ()) "%d %d" (fun n k -> (n, k))
let p_list = List.map (fun n -> int_of_string n) (String.split_on_char ' ' (read_line ()))
let () = printf "%d\n" (mix_juice n k p_list)