import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.IntMap as IM

type Map = IM.IntMap Int

readIntsLine :: IO [Int]
readIntsLine = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

solve :: Int -> Int -> Map -> [Int]
solve (-1) _ _ = []
solve n k m = min r1 r2 : solve (n - 1) k m
  where l = fromJust $ IM.lookup n m
        r = fromJust $ IM.lookup (n + k - 1) m
        r1 = abs l + abs (r - l)
        r2 = abs r + abs (r - l)

main :: IO ()
main = do
  [n, k] <- readIntsLine
  xs <- zip [0..] <$> readIntsLine
  print . minimum . solve (n - k) k $ IM.fromList xs