import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B

main=B.interact$B.pack.show.f.unfoldr(B.readInt.B.dropWhile isSpace)
f (n:k:xs)
    | null mxs = pxs !! (k-1)
    | otherwise = a
    where
        (mxs,pxs) = span (<0) xs
        lm = length mxs
        ps = drop (max 0 (k-lm)) (0:take k pxs)
        as = zip ps $ drop (max 0 (lm-k)) $ map (0-) mxs
        a = minimum $ concatMap (\(a,b)->[a*2+b,a+b*2]) as
