
import Data.List

main = (taskSchedule <$> getLine) >>= print

hoge = taskSchedule <$> getLine

taskSchedule x = minimum $ map (foldr1 (+)) $ map (\x -> zipWith (\a b -> abs (a-b)) (init x ) (tail x)) $ permutations $ map read $ words x 