{-# OPTIONS_GHC -O2 #-}

import Control.Arrow
import Control.Monad
import qualified Data.ByteString.Char8 as C
import Data.Char
import Data.List
import Data.Monoid
import Data.Ord
import qualified Data.Vector.Unboxed as U
import System.IO

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

main = do
    n <- readLn
    as <- r n
    print $ (uncurry subtract) $ (U.minimum &&& U.sum) as
