import qualified Data.Vector as V

solve :: Int -> Int -> V.Vector Int -> Int
solve n k xs = (\t -> if null t then 0 else minimum t) $ map (\i -> dist (xs V.! i) (xs V.! (i+k-1))) [0..n-k] where
  dist x y =
    let
      l = max (-x) 0
      r = max y 0
    in
      l + r + min l r

main = do
  [n,k] <- fmap read . words <$> getLine
  xs <- fmap read . words <$> getLine
  print $ solve n k $ V.fromList xs

