import           Control.Arrow         (second)
import           Data.Char             (isSpace)
import           Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BSC8
import           Data.List             (sort, unfoldr)
import           Data.Vector.Unboxed   (Vector)
import qualified Data.Vector.Unboxed   as UV

getIL :: IO [Int]
getIL = unfoldr f <$> BSC8.getLine
  where
    -- f :: ByteString -> Maybe (Int, ByteString)
    f s = do
      (n, s') <- BSC8.readInt s
      return (n, BSC8.dropWhile isSpace s')

main :: IO ()
main = do
  (_:k:_) <- getIL
  ps <- getIL
  print $ sum . take k . sort $ ps
