open Batteries

let n,k = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a, b))
let () = read_line ()
  |> String.split_on_char ' '
  |> List.map int_of_string
  |> List.sort compare
  |> List.rev
  |> Batteries.List.take k
  |> List.fold_left (+) 0
  |> Printf.sprintf "%d"
  |> print_endline