import Data.List

main :: IO ()
main = do
  n <- readLn :: IO Int
  xs <- reverse . sort . map read . words <$> getLine :: IO [Int]
  print $ game xs

game :: [Int] -> Int
game [] = 0
game [x] = x
game (x:y:xs) = x-y + game xs