
import qualified Data.Vector as V

lowerBound :: Ord a => a -> V.Vector a -> Int
lowerBound x xs = go (-1) (V.length xs) where
  go l r
    | l==r-1 = r
    | x<=(xs V.! m) = go l m
    | otherwise = go m r
    where m = (l+r)`div`2

inf = 1000000000

solv :: V.Vector Int -> Int -> Int
solv xs k = go inf rini (k-rini) where
  base = lowerBound 0 xs
  rini = min k base
  go m r l
    | r<0 || l+base>V.length xs = m
    | r==0 = go (min m ld) (r-1) (l+1)
    | l==0 = go (min m rd) (r-1) (l+1)
    | otherwise = go (min m (min (2*rd+ld) (rd+2*ld))) (r-1) (l+1)
    where
      rd = if r==0 then 0 else abs $ xs V.!(base-r)
      ld = if l==0 then 0 else abs $ xs V.!(base+l-1)


main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  xs <- V.fromList . map read . words <$> getLine
  print $ solv xs k
  