import Control.Applicative ((<$>), (<*>))
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = do
  B.getLine
  solve <$> getl (readil B.readInt) >>= print

solve :: [Int] -> Int
solve = f 0 . sortBy (flip compare)
  where
    f d []  = d
    f d [x] = d + x
    f d (x:y:ys) = f (d + x - y) ys
      
getl :: (ByteString -> a) -> IO a
getl f = f <$> B.getLine

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')
