open Str

module L =
  struct
    include List
  
    let rec take n = function
        [] -> []
      | h :: t when n > 0 -> h :: take (n - 1) t
      | _ -> []

    let sum ls =
      fold_left (+) 0 ls
  end
    
let flip f x y = f y x

let read_list f =
  split (regexp " +") (read_line ()) |> List.map f

let () = 
  let n, k = match read_list int_of_string with
      a :: b :: _ -> (a, b)
    | _ -> failwith "read_list" in
  let ls = read_list int_of_string in
  L.sort (flip compare) ls |> L.take k |> L.sum |> string_of_int |> print_endline
