import Control.Monad
import Data.List
import Control.Arrow

getInts :: IO [Int]
getInts = do s <- getLine
             return $ map read $ words s

getLines :: Int -> IO [String]
getLines n = replicateM n $ getLine


takeN :: Int -> [Int] -> [(Int, Int)]
takeN k xs = zip xs (drop (k-1) xs)

cost :: (Int, Int) -> Int
cost (n, x) = let mn = - minimum [0, n, x]
                  mx = maximum [0, n, x]
              in (mn * 2 + mx) `min` (mx * 2 + mn)


main = do [n, k] <- getInts
          xs <- getInts
          let res = minimum [ cost pr | pr <- takeN k xs ]
          print res
