let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let (n, k) = Scanf.sscanf (read_line ()) "%d %d" @@ fun n k -> (n, k)
let p = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> List.sort compare

let rec loop sum i acc =
    if i = 0 then Printf.printf "%d\n" sum
    else loop (sum + List.hd acc) (i - 1) (List.tl acc)

let () = loop 0 k p