import           Data.List (delete)

main :: IO()
main = do
  [q,n] <- words <$> getLine
  x <- getLine
  if "0" `elem` words x
    then print $ minimum $ canSort 0 (read n-1) (filter (<0) (map read (words x))) (filter (>0) (map read (words x))) 0
    else print $ minimum $ canSort 0 (read n) (filter (<0) (map read (words x))) (filter (>0) (map read (words x))) 0

--左の木(last)と右の木(head)
canSort :: Int -> Int -> [Int] -> [Int] -> Int -> [Int]
canSort _   0 _  _  x = [x]
canSort acc n [] rs x = canSort (head rs) (n-1) [] (tail rs) (x + abs (acc - head rs))
canSort acc n ls [] x = canSort (last ls) (n-1) (init ls) [] (x + abs (acc - last ls))
canSort acc n ls rs x = canSort (last ls) (n-1) (init ls) rs (x + abs (acc - last ls)) ++
                        canSort (head rs) (n-1) ls (tail rs) (x + abs (acc - head rs))
