open Batteries
let n,k = Scanf.sscanf (read_line()) "%d %d" (fun n k -> n,k)
let p = read_line()|>String.split_on_char ' ' |> List.map int_of_string |> List.sort compare
let _ = (List.fold_left (fun a b -> a + b) 0 (List.init k @@ fun o -> List.nth p o)) |> Printf.printf "%d\n"