import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = getLine >> breads >>= print . solve 

solve :: [Int] -> Int
solve = calc . fst . foldl' ff ((0, 0), True) . sortBy (flip compare)
    where
        ff ((acc, bcc), f) n
            | f = ((acc + n, bcc), False)
            | otherwise = ((acc, bcc + n), True)
        calc (acc, bcc) = acc - bcc

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)