module Main where

import Control.Applicative
import Control.Monad

chunk :: Int -> [a] -> [[a]]
chunk n xs
    | length xs >= n = take n xs : chunk n (tail xs)
    | otherwise      = []

dst :: [Int] -> Int
dst xs = abs $ last xs - head xs

loop :: [[Int]] -> Int
loop (as:ass) = iter as (head as) (last as) ass
  where
    iter _  a b [] = min (abs a) (abs b) + abs (b - a)
    iter ys a b (xs:xss) =
        let c = head xs
            d = last xs
        in case abs (b - a) `compare` abs (d - c) of
            LT -> iter ys a b xss
            GT -> iter xs c d xss
            EQ -> if min (abs a) (abs b) <= min (abs c) (abs d)
                  then iter ys a b xss
                  else iter xs c d xss

main :: IO ()
main = do
    [n, k] <- fmap read . words <$> getLine :: IO [Int]
    xs <- fmap read . words <$> getLine :: IO [Int]
    if k == 1
        then print $ minimum $ fmap abs xs
        else print $ loop $ chunk k xs