module Main where

import Data.List (nub)

getNums :: IO [Integer]
getNums = map (read :: String -> Integer) . words <$> getLine

sort :: (Ord a) => [a] -> [a]
sort = mergeAll . map (:[]) 
  where
    mergeAll [] = []
    mergeAll [t] = t
    mergeAll xs  = mergeAll (mergePairs xs)

    mergePairs (x:y:xs) = merge x y:mergePairs xs
    mergePairs xs = xs

merge :: Ord a => [a] -> [a] -> [a]
merge [] ys         = ys
merge xs []         = xs
merge (x:xs) (y:ys) | x < y     = x:merge xs (y:ys)
                    | otherwise = y:merge (x:xs) ys

main :: IO ()
main = do
    [n, m] <- map (read :: String -> Int) . words <$> getLine
    as <- getNums
    let guests = reverse . sort $ zip as [1,2..]
    let pairs = nub [(a, b) | a <- guests, b <- guests]
    let pairs' = map (\((v, i), (v', i')) -> (v, v')) pairs
    let shakeValues = reverse . sort $ map (\(a, b) -> a + b) pairs'

    let result = foldr (+) 0 (take m shakeValues)

    putStrLn $ show result