import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord

main :: IO ()
main = breads >>= main'
    where
        main' [_, k] = breads >>= print . solve k 

-- |
-- >>> solve 3 [-30, -10, 10, 20, 50]
-- 40
-- >>> solve 2 [10, 20, 30]
-- 20
-- >>> solve 1 [0]
-- 0
-- >>> solve 5 [-9, -7, -4, -3, 1, 2, 3, 4]
-- 10
solve :: Int -> [Int] -> Int
solve 1 xs = head $ sortBy (comparing abs) xs
solve k xs = search len (tail xs) bs
    where
        (b : bs) = drop (k - 1) xs
        len = calc (head xs) b

        search res (y : ys) (z : zs) = search (min res $ calc y z) ys zs
        search res _ _ = res

        calc minv maxv
            | minv >= 0 = maxv 
            | maxv <= 0 = abs minv
            | otherwise = abs minv + maxv + min (abs minv) maxv


breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine