Scanf.scanf "%d %d" (fun n k ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;
    let rec loop i sum =
        if i = k then sum else loop (i + 1) (sum + a.(i))
    in
    loop 0 0 |> Printf.printf "%d\n"
)