{-Prelude> let delete x xs = filter (/= x) xs
Prelude> delete 3 [1..9]
[1,2,4,5,6,7,8,9]
-}
import Data.List

main :: IO ()
main = do
    n <- getLine
    as <- map read . words <$> getLine
    putStrLn $ show(tensa as)

tensa :: [Int] -> Int
tensa xs =  if xs == [] then 0
            else maximum xs - tensa ( delete (maximum xs) xs)