(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n, k = Scanf.sscanf (read_line ()) "%d %d" ( fun n k -> n, k)
let lst = Str.split (Str.regexp " ") (read_line ())
          |> List.map int_of_string
          |> List.sort compare
          |> List.mapi (fun i elmnt ->
                  if i < k then
                          elmnt
                  else
                          0
          ) 

let () =
        List.sum lst
        |> Printf.printf "%d\n"
