open Array let () = let n, k = Scanf.scanf "%d %d\n" @@ fun a b -> a, b in let lst = to_list (init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d) in let rec f lst k = if k = 0 then 0 else match lst with | [] -> 0 | h :: t -> if h > 0 then h + f t (k-1) else 0 in List.fast_sort compare lst; print_int (f lst k)