let rec take n = function
  | [] -> []
  | x :: xs ->
      if n = 0 then []
      else x :: take (n - 1) xs

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  Array.init n (fun _ ->
    Scanf.scanf "%d " @@ fun l -> l)
  |> Array.to_list
  |> List.sort (fun x y -> compare y x)
  |> take k
  |> List.fold_left ( + ) 0
  |> Printf.printf "%d\n"
