import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Char

solve :: VU.Vector Int -> Int -> Int
solve xs k
    | VU.length xs < k = 10^9 
    | i >= 0 = min (dist + (abs $ 0 - i)) (solve (VU.tail xs) k)
    | j <= 0 = min (dist + (abs $ 0 - j)) (solve (VU.tail xs) k)
    | otherwise = min (dist + min (abs $ 0 - i) (abs $ 0 - j)) (solve (VU.tail xs) k)
    where
        grids = VU.take k xs
        i = grids VU.! 0
        j = grids VU.! (k-1) 
        dist = abs $ i - j 

main = do
    [n,k] <- map read . words <$> getLine
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    print $ solve xs k