defmodule Main do
  def main do
    [_n, k] = IO.gets("") |> String.trim() |> String.split() |> Enum.map(&String.to_integer/1)

    IO.gets("")
    |> String.trim()
    |> String.split()
    |> Enum.map(&String.to_integer/1)
    |> Enum.sort()
    |> Enum.take(k)
    |> Enum.sum()
    |> IO.puts()
  end
end