import Control.Monad
import Control.Applicative

qsort :: [Int] -> [Int]
qsort []     = []
qsort (p:xs) = qsort lt ++ [p] ++ qsort gteq
    where lt   = [x | x <- xs, x <  p]
          gteq = [x | x <- xs, x >= p]

solver' :: [Int] -> Int -> Int
solver' []     _ = 0
solver' (x:xs) p = abs (x - p) + solver' xs p

solver :: [Int] -> Int
solver (x:xs) = solver' ((tail . qsort) xs) x

main :: IO ()
main = getLine >>= print . solver . (map read) . words
