let () =
  Scanf.scanf "%d %d\n" @@ fun n k ->
  let prr = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ fun d -> d in
  let () = Array.fast_sort compare prr in
  let plst = Array.to_list prr in
  let rec sumk lst k = if k = 0 then 0 else (List.hd lst) + sumk (List.tl lst) (k-1) in
  Printf.printf "%d\n" (sumk plst k)