open Printf
open Scanf

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

    let sum = fold_left (+) 0
  end

let id x = x

let solve n k =
  let ps = L.init n @@ fun _ -> scanf "%d " id in
  L.sum @@ L.take k @@ List.sort compare ps
          
let () =
  scanf "%d %d " solve |> printf "%d\n"
