import Data.List (sort)

solve :: Integral a => [a] -> a
solve = sol . sort
    where
        sol [] = 0
        sol [_] = 0
        sol (x : y : zs) = min x y + sol zs

main :: IO ()
main = do
    _ <- getLine
    print . solve . fmap (read :: String -> Int) . words =<< getLine
