defmodule Main do
  def main do
    [n,k]=IO.gets("") |> String.trim |>String.split(" ") |> Enum.map(fn x->String.to_integer(x)end)
    IO.gets("") |> String.trim |> String.split(" ") |>Enum.map(fn x->String.to_integer(x)end)
    |> Enum.sort() |> Enum.slice(0..k-1) |>Enum.sum() 
    |>IO.puts()
  end
end
